fix(HtmlParser): mark <source> elements as void
Fixes #5663 Closes #5668
This commit is contained in:
parent
86c74cf3f3
commit
50490b55eb
|
@ -310,11 +310,16 @@ export class HtmlTagDefinition {
|
||||||
// see http://www.w3.org/TR/html51/syntax.html#optional-tags
|
// see http://www.w3.org/TR/html51/syntax.html#optional-tags
|
||||||
// This implementation does not fully conform to the HTML5 spec.
|
// This implementation does not fully conform to the HTML5 spec.
|
||||||
var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = {
|
var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = {
|
||||||
|
'area': new HtmlTagDefinition({isVoid: true}),
|
||||||
|
'embed': new HtmlTagDefinition({isVoid: true}),
|
||||||
'link': new HtmlTagDefinition({isVoid: true}),
|
'link': new HtmlTagDefinition({isVoid: true}),
|
||||||
'img': new HtmlTagDefinition({isVoid: true}),
|
'img': new HtmlTagDefinition({isVoid: true}),
|
||||||
'input': new HtmlTagDefinition({isVoid: true}),
|
'input': new HtmlTagDefinition({isVoid: true}),
|
||||||
|
'param': new HtmlTagDefinition({isVoid: true}),
|
||||||
'hr': new HtmlTagDefinition({isVoid: true}),
|
'hr': new HtmlTagDefinition({isVoid: true}),
|
||||||
'br': new HtmlTagDefinition({isVoid: true}),
|
'br': new HtmlTagDefinition({isVoid: true}),
|
||||||
|
'source': new HtmlTagDefinition({isVoid: true}),
|
||||||
|
'track': new HtmlTagDefinition({isVoid: true}),
|
||||||
'wbr': new HtmlTagDefinition({isVoid: true}),
|
'wbr': new HtmlTagDefinition({isVoid: true}),
|
||||||
'p': new HtmlTagDefinition({
|
'p': new HtmlTagDefinition({
|
||||||
closedByChildren: [
|
closedByChildren: [
|
||||||
|
@ -357,7 +362,7 @@ var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = {
|
||||||
}),
|
}),
|
||||||
'td': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
|
'td': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
|
||||||
'th': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
|
'th': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
|
||||||
'col': new HtmlTagDefinition({closedByChildren: ['col'], requiredParents: ['colgroup']}),
|
'col': new HtmlTagDefinition({requiredParents: ['colgroup'], isVoid: true}),
|
||||||
'svg': new HtmlTagDefinition({implicitNamespacePrefix: 'svg'}),
|
'svg': new HtmlTagDefinition({implicitNamespacePrefix: 'svg'}),
|
||||||
'math': new HtmlTagDefinition({implicitNamespacePrefix: 'math'}),
|
'math': new HtmlTagDefinition({implicitNamespacePrefix: 'math'}),
|
||||||
'li': new HtmlTagDefinition({closedByChildren: ['li'], closedByParent: true}),
|
'li': new HtmlTagDefinition({closedByChildren: ['li'], closedByParent: true}),
|
||||||
|
|
|
@ -75,6 +75,19 @@ export function main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not error on void elements from HTML5 spec',
|
||||||
|
() => { // http://www.w3.org/TR/html-markup/syntax.html#syntax-elements without:
|
||||||
|
// <base> - it can be present in head only
|
||||||
|
// <meta> - it can be present in head only
|
||||||
|
// <command> - obsolete
|
||||||
|
// <keygen> - obsolete
|
||||||
|
['<map><area></map>', '<div><br></div>', '<colgroup><col></colgroup>',
|
||||||
|
'<div><embed></div>', '<div><hr></div>', '<div><img></div>', '<div><input></div>',
|
||||||
|
'<object><param>/<object>', '<audio><source></audio>', '<audio><track></audio>',
|
||||||
|
'<p><wbr></p>',
|
||||||
|
].forEach((html) => { expect(parser.parse(html, 'TestComp').errors).toEqual([]); });
|
||||||
|
});
|
||||||
|
|
||||||
it('should close void elements on text nodes', () => {
|
it('should close void elements on text nodes', () => {
|
||||||
expect(humanizeDom(parser.parse('<p>before<br>after</p>', 'TestComp')))
|
expect(humanizeDom(parser.parse('<p>before<br>after</p>', 'TestComp')))
|
||||||
.toEqual([
|
.toEqual([
|
||||||
|
|
Loading…
Reference in New Issue