Skip to content

Commit

Permalink
Allow HTML comments containing "--" even though it is not allowed by …
Browse files Browse the repository at this point in the history
…the CommonMark specification because it is allowed by the HTML specification and it happens in real life (fixes #996).
  • Loading branch information
DavidAnson committed Oct 8, 2023
1 parent d2faf40 commit 6eca6f1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
10 changes: 9 additions & 1 deletion demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,16 @@ function isHtmlFlowComment(token) {
type = token.type;
if (type === "htmlFlow" && text.startsWith("<!--") && text.endsWith("-->")) {
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;
}

Expand Down
9 changes: 7 additions & 2 deletions helpers/micromark.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions test/front-matter-yaml-in-html-comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
---
title: Front Matter YAML in HTML Comment
not-md035: |-
***
* * *
description: |-
This document has YAML front matter inside an HTML comment.
---
-->

# Front Matter YAML in HTML Comment

Text text text
23 changes: 23 additions & 0 deletions test/snapshots/markdownlint-test-scenarios.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13866,6 +13866,29 @@ Generated by [AVA](https://avajs.dev).
`,
}

## front-matter-yaml-in-html-comment.md

> Snapshot 1

{
errors: [],
fixed: `<!--␊
---␊
title: Front Matter YAML in HTML Comment␊
not-md035: |-␊
***␊
* * *␊
description: |-␊
This document has YAML front matter inside an HTML comment.␊
---␊
-->␊
# Front Matter YAML in HTML Comment␊
Text text text␊
`,
}

## front-matter.md

> Snapshot 1
Expand Down
Binary file modified test/snapshots/markdownlint-test-scenarios.js.snap
Binary file not shown.

0 comments on commit 6eca6f1

Please sign in to comment.