html2jade icon indicating copy to clipboard operation
html2jade copied to clipboard

attribute case is not preserved when converting from html

Open pdeva opened this issue 9 years ago • 13 comments

Eg- this piece of code from a valid angular template becomes error prone when converted to jade cause ngModel is converted to ngmodel


<div class="container">
  <h1>User info</h1>
  <form (ngSubmit)="onSubmit()">
    <div class="form-group">
      <label>User Email</label>
      <input type="text" [(ngModel)]="email" ngControl="email" #spy="" required="" class="form-control"/>
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
</div>

pdeva avatar Dec 28 '15 03:12 pdeva

As you probably know tag and attribute names are case-insensitive in HTML and common convention is to use lower-case which got slipped into html2jade at some point for reasons I don't recall.

I just checked Jade and it does preserve attribute name case.

Since I don't want to introduce incompatibility with previous versions, I'll have to add an optional flag to preserve tag and attribute name case.

Can you tell me why you need attribute names' case to be preserved so I can understand your use-case?

donpark avatar Dec 28 '15 13:12 donpark

angular2 template syntax needs this. without this fix anyone using html to jade with angular2 template will run into issues

On Monday, December 28, 2015, Don Park [email protected] wrote:

As you probably know tag and attribute names are case-insensitive in HTML and common convention is to use lower-case which got slipped into html2jade at some point for reasons I don't recall.

I just checked Jade and it does preserve attribute name case.

Since I don't want to introduce incompatibility with previous versions, I'll have to add an optional flag to preserve tag and attribute name case.

Can you tell me why you need attribute names' case to be preserved so I can understand your use-case?

— Reply to this email directly or view it on GitHub https://github.com/donpark/html2jade/issues/102#issuecomment-167566054.

Prashant

pdeva avatar Dec 28 '15 16:12 pdeva

@pdeva it turns out lowercasing of attribute name is done at DOM layer before html2jade sees them which means html2jade will have to either use HTML parser directly or find a DOM implementation that preserves attribute name case.

Unfortunately, neither options are pursuable time-wise. Punting for revisit later.

donpark avatar Dec 29 '15 00:12 donpark

Just remembered that Angular uses two forms for attributes: dashed (like ng-model) and camelcased (like ngModel), later form intended for use in JavaScript.

Since I can't address this issue at this time, my suggested workaround is to write a short JS script that changes anything like "ngFoobar" to "ng-foobar". Sorry, this is the best I can do at this time. :-(

donpark avatar Dec 29 '15 00:12 donpark

the dashed form is no longer supported since angular2 beta

Prashant

On Mon, Dec 28, 2015 at 4:16 PM, Don Park [email protected] wrote:

Just remembered that Angular uses two forms for attributes: dashed (like ng-model) and camelcased (like ngModel), later form intended for use in JavaScript.

Since I can't address this issue at this time, my suggested workaround is to write a short JS script that changes anything like "ngFoobar" to "ng-foobar". Sorry, this is the best I can do at this time. :-(

— Reply to this email directly or view it on GitHub https://github.com/donpark/html2jade/issues/102#issuecomment-167682596.

pdeva avatar Dec 29 '15 00:12 pdeva

do you have a link to an official doc saying that? I haven't been able to find any. - Don

donpark avatar Dec 29 '15 05:12 donpark

+1

Here is example from docs https://angular.io/docs/ts/latest/api/common/NgFor-directive.html

Syntax

<li *ngFor="#item of items; #i = index">...</li>
<li template="ngFor #item of items; #i = index">...</li>
<template ngFor #item [ngForOf]="items" #i="index"><li>...</li></template>

Selectors

[ngFor][ngForOf]

I added failing test at https://github.com/tb/html2jade/commit/53e954b5a120ec5b92edc05ac474cb7e1887bf5a

tb avatar Feb 13 '16 12:02 tb

thx for the example @tb but as I wrote above html2jade uses DOM API to support client-side generated HTML and thus only sees DOM normalized lowercased attribute names so this functionality cannot be implemented without uprooting everything.

When I get some spare time, I will look into htmlparser2, below DOM layer, which may expose the original attribute names and see whether it makes sense to switch or writing a completely new tool based on textual input makes more sense.

donpark avatar Feb 13 '16 14:02 donpark

Thanks for your work on this, @donpark, I'm also running into a case where tags and attribute name cases must be preserved.. on the fringe here :)

jonscottclark avatar Feb 16 '16 15:02 jonscottclark

Another use case — SVG names, like XML, are also case-sensitive.

thatmarvin avatar Mar 30 '16 16:03 thatmarvin

Another case is almost all react components are title cased

hsingh23 avatar Dec 05 '16 19:12 hsingh23

+1

m-farahmand avatar May 02 '18 14:05 m-farahmand

Hi all. I've noticed that jsdom now supports xml parsing mode, enabling case-sensitivity, but my simple attempt to upgrade the module turned sour fast due to how much node and jsdom itself has changed over the years.

Thankfully, there is another relatively new module named html2pug and it appears to support case-sensitive conversion.

donpark avatar May 08 '18 00:05 donpark