diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 5cec4c6e6..6d1c481e4 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -1217,8 +1217,16 @@ function isHtmlFlowComment(token) { type = token.type; if (type === "htmlFlow" && text.startsWith("")) { var comment = text.slice(4, -3); - return !comment.startsWith(">") && !comment.startsWith("->") && !comment.endsWith("-") && !comment.includes("--"); + return !comment.startsWith(">") && !comment.startsWith("->") && !comment.endsWith("-") + // The following condition from the CommonMark specification is commented + // to avoid parsing HTML comments that include "--" because that is NOT a + // condition of the HTML specification. + // https://spec.commonmark.org/0.30/#raw-html + // https://html.spec.whatwg.org/multipage/syntax.html#comments + // && !comment.includes("--") + ; } + return false; } diff --git a/helpers/micromark.cjs b/helpers/micromark.cjs index 9603131ce..f247ebe52 100644 --- a/helpers/micromark.cjs +++ b/helpers/micromark.cjs @@ -42,8 +42,13 @@ function isHtmlFlowComment(token) { return ( !comment.startsWith(">") && !comment.startsWith("->") && - !comment.endsWith("-") && - !comment.includes("--") + !comment.endsWith("-") + // The following condition from the CommonMark specification is commented + // to avoid parsing HTML comments that include "--" because that is NOT a + // condition of the HTML specification. + // https://spec.commonmark.org/0.30/#raw-html + // https://html.spec.whatwg.org/multipage/syntax.html#comments + // && !comment.includes("--") ); } return false; diff --git a/test/front-matter-yaml-in-html-comment.md b/test/front-matter-yaml-in-html-comment.md new file mode 100644 index 000000000..b90019e58 --- /dev/null +++ b/test/front-matter-yaml-in-html-comment.md @@ -0,0 +1,14 @@ + + +# Front Matter YAML in HTML Comment + +Text text text diff --git a/test/snapshots/markdownlint-test-scenarios.js.md b/test/snapshots/markdownlint-test-scenarios.js.md index d3a080924..eafeaaf80 100644 --- a/test/snapshots/markdownlint-test-scenarios.js.md +++ b/test/snapshots/markdownlint-test-scenarios.js.md @@ -13866,6 +13866,29 @@ Generated by [AVA](https://avajs.dev). `, } +## front-matter-yaml-in-html-comment.md + +> Snapshot 1 + + { + errors: [], + fixed: `␊ + ␊ + # Front Matter YAML in HTML Comment␊ + ␊ + Text text text␊ + `, + } + ## front-matter.md > Snapshot 1 diff --git a/test/snapshots/markdownlint-test-scenarios.js.snap b/test/snapshots/markdownlint-test-scenarios.js.snap index d604f4229..dd6c0c0d3 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.js.snap and b/test/snapshots/markdownlint-test-scenarios.js.snap differ