mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Change comment replacement character from " " (with trailing "\") to "." to avoid creating indented code blocks.
This commit is contained in:
parent
c4e236b858
commit
c7d2416f95
4 changed files with 45 additions and 36 deletions
|
@ -112,9 +112,8 @@ module.exports.includesSorted = function includesSorted(array, element) {
|
|||
}
|
||||
return false;
|
||||
};
|
||||
// Replaces the text of all properly-formatted HTML comments with whitespace
|
||||
// Replaces the content of properly-formatted CommonMark comments with "."
|
||||
// This preserves the line/column information for the rest of the document
|
||||
// Trailing whitespace is avoided with a '\' character in the last column
|
||||
// https://spec.commonmark.org/0.29/#html-blocks
|
||||
// https://spec.commonmark.org/0.29/#html-comment
|
||||
var htmlCommentBegin = "<!--";
|
||||
|
@ -147,12 +146,9 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
|||
.search(inlineCommentRe);
|
||||
// If not a markdownlint inline directive...
|
||||
if (inlineCommentIndex === -1) {
|
||||
var blanks = content
|
||||
.replace(/[^\r\n]/g, " ")
|
||||
.replace(/ ([\r\n])/g, "\\$1");
|
||||
text =
|
||||
text.slice(0, i + htmlCommentBegin.length) +
|
||||
blanks +
|
||||
content.replace(/[^\r\n]/g, ".") +
|
||||
text.slice(j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,9 +99,8 @@ module.exports.includesSorted = function includesSorted(array, element) {
|
|||
return false;
|
||||
};
|
||||
|
||||
// Replaces the text of all properly-formatted HTML comments with whitespace
|
||||
// Replaces the content of properly-formatted CommonMark comments with "."
|
||||
// This preserves the line/column information for the rest of the document
|
||||
// Trailing whitespace is avoided with a '\' character in the last column
|
||||
// https://spec.commonmark.org/0.29/#html-blocks
|
||||
// https://spec.commonmark.org/0.29/#html-comment
|
||||
const htmlCommentBegin = "<!--";
|
||||
|
@ -134,12 +133,9 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
|||
.search(inlineCommentRe);
|
||||
// If not a markdownlint inline directive...
|
||||
if (inlineCommentIndex === -1) {
|
||||
const blanks = content
|
||||
.replace(/[^\r\n]/g, " ")
|
||||
.replace(/ ([\r\n])/g, "\\$1");
|
||||
text =
|
||||
text.slice(0, i + htmlCommentBegin.length) +
|
||||
blanks +
|
||||
content.replace(/[^\r\n]/g, ".") +
|
||||
text.slice(j);
|
||||
}
|
||||
}
|
||||
|
|
17
test/html-comment-in-markdown-table.md
Normal file
17
test/html-comment-in-markdown-table.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# HTML Comment in Markdown Table
|
||||
|
||||
```xml
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
| Table |
|
||||
|-------|
|
||||
| <!-- |
|
||||
|comment|
|
||||
| --> |
|
||||
|
||||
| Table |
|
||||
|-------|
|
||||
| <!-- \
|
||||
\
|
||||
--> |
|
|
@ -56,17 +56,17 @@ test("clearHtmlCommentTextValid", (t) => {
|
|||
"<!-->",
|
||||
"<!--->",
|
||||
"<!---->",
|
||||
"<!--.........-->",
|
||||
" <!--.........-->",
|
||||
" <!--.........-->",
|
||||
"<!--......-->",
|
||||
"<!--....-->",
|
||||
"<!--.-->",
|
||||
"<!--....-->",
|
||||
"<!---->",
|
||||
" <!-- -->",
|
||||
" <!-- -->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!---->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!-- -->",
|
||||
"<!--.....-->",
|
||||
"<!--.........-->",
|
||||
"<!--..-->",
|
||||
"<!--",
|
||||
"-->",
|
||||
"<!--",
|
||||
|
@ -78,21 +78,21 @@ test("clearHtmlCommentTextValid", (t) => {
|
|||
"-->",
|
||||
"<!--",
|
||||
"",
|
||||
" \\",
|
||||
"......",
|
||||
"",
|
||||
"-->",
|
||||
"<!-- \\",
|
||||
"<!--....",
|
||||
"",
|
||||
" -->",
|
||||
"text<!-- -->text",
|
||||
"....-->",
|
||||
"text<!--....-->text",
|
||||
"text<!--",
|
||||
"-->text",
|
||||
"text<!--",
|
||||
" \\",
|
||||
"....",
|
||||
"-->text",
|
||||
"<!-- --><!-- -->",
|
||||
"text<!-- -->text<!-- -->text",
|
||||
"text<!-- -->text",
|
||||
"<!--....--><!--....-->",
|
||||
"text<!--....-->text<!--....-->text",
|
||||
"text<!--..............-->text",
|
||||
"<!--",
|
||||
"text"
|
||||
];
|
||||
|
@ -133,9 +133,9 @@ test("clearHtmlCommentTextNonGreedy", (t) => {
|
|||
"<!----> -->"
|
||||
];
|
||||
const nonGreedyResult = [
|
||||
"<!-- --> -->",
|
||||
"<!-- --> -->",
|
||||
"<!-- --> -->",
|
||||
"<!--......--> -->",
|
||||
"<!--......--> -->",
|
||||
"<!--.--> -->",
|
||||
"<!----> -->"
|
||||
];
|
||||
const actual = helpers.clearHtmlCommentText(nonGreedyComments.join("\n"));
|
||||
|
@ -153,11 +153,11 @@ test("clearHtmlCommentTextEmbedded", (t) => {
|
|||
"text<!--text-->text"
|
||||
];
|
||||
const embeddedResult = [
|
||||
"text<!-- -->text",
|
||||
"text<!--....-->text",
|
||||
"<!-- markdownlint-disable MD010 -->",
|
||||
"text<!-- -->text",
|
||||
"text<!--....-->text",
|
||||
"text<!-- markdownlint-disable MD010 -->text",
|
||||
"text<!-- -->text"
|
||||
"text<!--....-->text"
|
||||
];
|
||||
const actual = helpers.clearHtmlCommentText(embeddedComments.join("\n"));
|
||||
const expected = embeddedResult.join("\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue