Skip to content

Commit

Permalink
Merge pull request #49 from ericeslinger/angularAttributes
Browse files Browse the repository at this point in the history
updated test and parser for [stuff] tags
  • Loading branch information
mrhanlon authored Jul 12, 2017
2 parents 34c50e2 + a46169d commit a701439
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parsers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ module.exports =
type: @name
length: 0
}
match = text.match(/^<(\/)?([^\s\/<>!][^\s\/<>]*)(\s+([\w-:]+)(=["'`{]([\S\s]*?)["'`}])?)*\s*(\/)?>/i)

match = text.match(/^<(\/)?([^\s\/<>!][^\s\/<>]*)(\s+([\w-:\[\]\(\)\*\@\#]+)(=["'`{]([\S\s]*?)["'`}])?)*\s*(\/)?>/i)
# match = text.match(/^<(\/)?([^\s\/<>!][^\s\/<>]*)(\s+([\w-:]+)(=["'`{]([\S\s]*?)["'`}])?)*\s*(\/)?>/i)
if match
result.element = match[2]
result.length = match[0].length
Expand Down
36 changes: 36 additions & 0 deletions spec/parsers-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,42 @@ describe "xmlparser", ->
length: 37
}

it "handles angular-style brackets", ->
text = "<div [ngClass]=\"{'foo': true}\">"
expect(xmlparser.parse(text)).toEqual {
opening: true
opening: true
closing: false
selfClosing: false
element: 'div'
type: 'xml'
length: 31
}

it "handles angular-style parentheses", ->
text = "<div (ngClass)=\"{'foo': true}\">"
expect(xmlparser.parse(text)).toEqual {
opening: true
opening: true
closing: false
selfClosing: false
element: 'div'
type: 'xml'
length: 31
}

it "handles angular-style special characters", ->
text = "<div @\#*ngClass=\"{'foo': true}\">"
expect(xmlparser.parse(text)).toEqual {
opening: true
opening: true
closing: false
selfClosing: false
element: 'div'
type: 'xml'
length: 32
}

it "works when property values are spread across multiple lines", ->
text = "<div\n style={\n fontFamily: \"Comic Sans MS\",\n }\n>"
expect(xmlparser.parse(text)).toEqual {
Expand Down

0 comments on commit a701439

Please sign in to comment.