Skip to content

Commit

Permalink
Added parsing angular's template (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexer2086 authored Jun 10, 2021
1 parent a68bf8f commit 628e1f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/htmlparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ export default class HTMLParser {
col: 1,
})

// Do not ignore validation inside <script type="ng/template"> template
const isMapCdataTagsRequired = () => {
const attrType = arrAttrs.find((attr) => attr.name === 'type') || {
value: '',
}

return (
mapCdataTags[tagName] &&
attrType.value.indexOf('text/ng-template') === -1
)
}

// Memory block
const saveBlock = (
type: string,
Expand Down Expand Up @@ -183,7 +195,7 @@ export default class HTMLParser {
close: match[6],
})

if (mapCdataTags[tagName]) {
if (isMapCdataTagsRequired()) {
tagCDATA = tagName
attrsCDATA = arrAttrs.concat()
arrCDATA = []
Expand Down
24 changes: 24 additions & 0 deletions test/htmlparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ describe('HTMLParser: Case parse', () => {
parser.parse('<link rel=icon /><link rel=icon />')
})

it('should parse special tag inside script template', (done) => {
const parser = new HTMLParser()
const arrEvents = []
getAllEvents(parser, arrEvents, () => {
expect(arrEvents[1]).to.event('tagstart', {
tagName: 'script',
})

const mapAttrs = parser.getMapAttrs(arrEvents[1].attrs)
expect(mapAttrs.type).to.be('text/ng-template')

expect(arrEvents[2]).to.event('tagstart', {
tagName: 'div',
})

expect(arrEvents[3]).to.event('tagend', {
tagName: 'script',
})

done()
})
parser.parse('<script type="text/ng-template"><div></script>')
})

it('should parse special empty attr', (done) => {
const parser = new HTMLParser()
const arrEvents = []
Expand Down

0 comments on commit 628e1f2

Please sign in to comment.