Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attribute case is not preserved when converting from html #102

Open
pdeva opened this issue Dec 28, 2015 · 13 comments
Open

attribute case is not preserved when converting from html #102

pdeva opened this issue Dec 28, 2015 · 13 comments
Labels

Comments

@pdeva
Copy link

pdeva commented Dec 28, 2015

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>
@donpark
Copy link
Owner

donpark commented Dec 28, 2015

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?

@pdeva
Copy link
Author

pdeva commented Dec 28, 2015

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 notifications@github.com 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
#102 (comment).

Prashant

@donpark
Copy link
Owner

donpark commented Dec 29, 2015

@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
Copy link
Owner

donpark commented Dec 29, 2015

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. :-(

@pdeva
Copy link
Author

pdeva commented Dec 29, 2015

the dashed form is no longer supported since angular2 beta

Prashant

On Mon, Dec 28, 2015 at 4:16 PM, Don Park notifications@github.com 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
#102 (comment).

@donpark
Copy link
Owner

donpark commented Dec 29, 2015

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

@tb
Copy link

tb commented Feb 13, 2016

+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 tb@53e954b

@donpark
Copy link
Owner

donpark commented Feb 13, 2016

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.

@jonscottclark
Copy link

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 :)

@thatmarvin
Copy link

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

@hsingh23
Copy link

hsingh23 commented Dec 5, 2016

Another case is almost all react components are title cased

@m-farahmand
Copy link

+1

@donpark
Copy link
Owner

donpark commented May 8, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants