Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…wercasing Angular JS attribute names
  • Loading branch information
prettydiff committed Apr 2, 2019
1 parent 3ba0a99 commit b2fc737
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lexers/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
} else if (eq < 0 && cft === undefined) {
// in most markup languages an attribute without an expressed value has its name
// as its string value
if (options.language === "html") {
if (options.language === "html" && attstore[ind][0].charAt(0) !== "#" && (/^\*?ng[A-Z]/).test(attstore[ind][0]) === false) {
record.token = attstore[ind][0].toLowerCase();
} else if (options.language === "xml" || options.language === "coldfusion") {
if (options.lexer_options.markup.quote_convert === "single") {
Expand All @@ -511,7 +511,7 @@
slice = "\"" + slice + "\"";
}
name = attstore[ind][0].slice(0, eq);
if (options.language === "html" && cft === undefined) {
if (options.language === "html" && cft === undefined && (/^\*?ng[A-Z]/).test(attstore[ind][0]) === false) {
name = name.toLowerCase();
}
if (options.language === "jsx" && (/^(\s*\{)/).test(slice) === true) {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"start": "node js/services build",
"test": "node js/services test"
},
"version": "1.1.0"
"version": "1.1.1"
}
21 changes: 21 additions & 0 deletions test/samples_code/markup/angular_language-html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h2>My Heroes</h2>

<div>
<label>Hero name:
<input #heroName />
</label>
<!-- (click) passes input value to add() and then clears the input -->
<button (click)="add(heroName.value); heroName.value=''">
add
</button>
</div>

<ul class="heroes">
<li *ngFor="let hero of heroes">
<a routerLink="/detail/{{hero.id}}">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</a>
<button class="delete" title="delete hero"
(click)="delete(hero)">x</button>
</li>
</ul>
37 changes: 37 additions & 0 deletions test/samples_parsed/markup/angular_language-html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{"begin":-1,"ender":2,"lexer":"markup","lines":0,"stack":"global","token":"<h2>","types":"start"},
{"begin":0,"ender":2,"lexer":"markup","lines":0,"stack":"h2","token":"My Heroes","types":"content"},
{"begin":0,"ender":2,"lexer":"markup","lines":0,"stack":"h2","token":"</h2>","types":"end"},
{"begin":-1,"ender":14,"lexer":"markup","lines":3,"stack":"global","token":"<div>","types":"start"},
{"begin":3,"ender":8,"lexer":"markup","lines":2,"stack":"div","token":"<label>","types":"start"},
{"begin":4,"ender":8,"lexer":"markup","lines":0,"stack":"label","token":"Hero name:","types":"content"},
{"begin":4,"ender":8,"lexer":"markup","lines":2,"stack":"label","token":"<input/>","types":"singleton"},
{"begin":6,"ender":8,"lexer":"markup","lines":1,"stack":"input","token":"#heroName","types":"attribute"},
{"begin":4,"ender":8,"lexer":"markup","lines":2,"stack":"label","token":"</label>","types":"end"},
{"begin":3,"ender":14,"lexer":"markup","lines":2,"stack":"div","token":"<!-- (click) passes input value to add() and then clears the input -->","types":"comment"},
{"begin":3,"ender":13,"lexer":"markup","lines":2,"stack":"div","token":"<button>","types":"start"},
{"begin":10,"ender":13,"lexer":"markup","lines":1,"stack":"button","token":"(click)=\"add(heroName.value); heroName.value=''\"","types":"attribute"},
{"begin":10,"ender":13,"lexer":"markup","lines":2,"stack":"button","token":"add","types":"content"},
{"begin":10,"ender":13,"lexer":"markup","lines":2,"stack":"button","token":"</button>","types":"end"},
{"begin":3,"ender":14,"lexer":"markup","lines":2,"stack":"div","token":"</div>","types":"end"},
{"begin":-1,"ender":34,"lexer":"markup","lines":3,"stack":"global","token":"<ul>","types":"start"},
{"begin":15,"ender":34,"lexer":"markup","lines":1,"stack":"ul","token":"class=\"heroes\"","types":"attribute"},
{"begin":15,"ender":33,"lexer":"markup","lines":2,"stack":"ul","token":"<li>","types":"start"},
{"begin":17,"ender":33,"lexer":"markup","lines":1,"stack":"li","token":"*ngFor=\"let hero of heroes\"","types":"attribute"},
{"begin":17,"ender":26,"lexer":"markup","lines":2,"stack":"li","token":"<a>","types":"start"},
{"begin":19,"ender":26,"lexer":"markup","lines":1,"stack":"a","token":"routerlink=\"/detail/{{hero.id}}\"","types":"attribute"},
{"begin":19,"ender":24,"lexer":"markup","lines":2,"stack":"a","token":"<span>","types":"start"},
{"begin":21,"ender":24,"lexer":"markup","lines":1,"stack":"span","token":"class=\"badge\"","types":"attribute"},
{"begin":21,"ender":24,"lexer":"markup","lines":0,"stack":"span","token":"{{hero.id}}","types":"template"},
{"begin":21,"ender":24,"lexer":"markup","lines":0,"stack":"span","token":"</span>","types":"end"},
{"begin":19,"ender":26,"lexer":"markup","lines":1,"stack":"a","token":"{{hero.name}}","types":"template"},
{"begin":19,"ender":26,"lexer":"markup","lines":2,"stack":"a","token":"</a>","types":"end"},
{"begin":17,"ender":32,"lexer":"markup","lines":2,"stack":"li","token":"<button>","types":"start"},
{"begin":27,"ender":32,"lexer":"markup","lines":1,"stack":"button","token":"class=\"delete\"","types":"attribute"},
{"begin":27,"ender":32,"lexer":"markup","lines":1,"stack":"button","token":"title=\"delete hero\"","types":"attribute"},
{"begin":27,"ender":32,"lexer":"markup","lines":2,"stack":"button","token":"(click)=\"delete(hero)\"","types":"attribute"},
{"begin":27,"ender":32,"lexer":"markup","lines":0,"stack":"button","token":"x","types":"content"},
{"begin":27,"ender":32,"lexer":"markup","lines":0,"stack":"button","token":"</button>","types":"end"},
{"begin":17,"ender":33,"lexer":"markup","lines":2,"stack":"li","token":"</li>","types":"end"},
{"begin":15,"ender":34,"lexer":"markup","lines":2,"stack":"ul","token":"</ul>","types":"end"}
]

0 comments on commit b2fc737

Please sign in to comment.