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

This commit is contained in:
Evilebot Tnawi authored and GitHub committed 2018-03-13 19:47:48 +03:00
1 parent 8686653433
commit e2373206bc
3 files changed
+35 -1

No files matched your search

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