fix(html): support comment on top (#4141)
parent
8686653433
commit
e2373206bc
|
@ -4,7 +4,7 @@ function parse(text /*, parsers, opts*/) {
|
|||
// Inline the require to avoid loading all the JS if we don't use it
|
||||
const parse5 = require("parse5");
|
||||
try {
|
||||
const isFragment = !/^\s*<(!doctype|html|head|body)/i.test(text);
|
||||
const isFragment = !/^\s*<(!doctype|html|head|body|!--)/i.test(text);
|
||||
const ast = (isFragment ? parse5.parseFragment : parse5.parse)(text, {
|
||||
treeAdapter: parse5.treeAdapters.htmlparser2,
|
||||
locationInfo: true
|
||||
|
|
|
@ -42,6 +42,33 @@ exports[`hello-world.html 1`] = `
|
|||
</html>
|
||||
`;
|
||||
|
||||
exports[`html-comments.html 1`] = `
|
||||
<!-- htmlhint attr-lowercase: false -->
|
||||
<html>
|
||||
<body>
|
||||
<a href="#">Anchor</a>
|
||||
<div hidden class="foo" id=bar></div>
|
||||
</body>
|
||||
</html>
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
<!-- htmlhint attr-lowercase: false -->
|
||||
|
||||
<html>
|
||||
|
||||
<head />
|
||||
|
||||
|
||||
<body>
|
||||
<a href="#">Anchor</a>
|
||||
<div hidden
|
||||
class="foo"
|
||||
id="bar" />
|
||||
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
exports[`html-fragment.html 1`] = `
|
||||
<a href="#">Link</a>
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<!-- htmlhint attr-lowercase: false -->
|
||||
<html>
|
||||
<body>
|
||||
<a href="#">Anchor</a>
|
||||
<div hidden class="foo" id=bar></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue