fix(html): support comment on top (#4141)

master
Evilebot Tnawi 2018-03-13 19:47:48 +03:00 committed by GitHub
parent 8686653433
commit e2373206bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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>

View File

@ -0,0 +1,7 @@
<!-- htmlhint attr-lowercase: false -->
<html>
<body>
<a href="#">Anchor</a>
<div hidden class="foo" id=bar></div>
</body>
</html>