diff --git a/src/language-html/parser-parse5.js b/src/language-html/parser-parse5.js index 59d3cb63d..98dca479d 100644 --- a/src/language-html/parser-parse5.js +++ b/src/language-html/parser-parse5.js @@ -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 diff --git a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap index 902d98bda..78435a2e6 100644 --- a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap @@ -42,6 +42,33 @@ exports[`hello-world.html 1`] = ` `; +exports[`html-comments.html 1`] = ` + + + + Anchor + + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + + + + + + + Anchor +