diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 703ca7f42..782c55738 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -377,7 +377,7 @@ module.exports.filterTokens = filterTokens; */ function getLineMetadata(params) { const lineMetadata = params.lines.map( - (line, index) => [ line, index, false, 0, false, false, false ] + (line, index) => [ line, index, false, 0, false, false, false, false ] ); filterTokens(params, "fence", (token) => { lineMetadata[token.map[0]][3] = 1; @@ -406,6 +406,11 @@ function getLineMetadata(params) { filterTokens(params, "hr", (token) => { lineMetadata[token.map[0]][6] = true; }); + filterTokens(params, "html_block", (token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][7] = true; + } + }); return lineMetadata; } module.exports.getLineMetadata = getLineMetadata; @@ -419,6 +424,7 @@ module.exports.getLineMetadata = getLineMetadata; * @param {boolean} inTable Iff in a table. * @param {boolean} inItem Iff in a list item. * @param {boolean} inBreak Iff in semantic break. + * @param {boolean} inHTML Iff in HTML. * @returns {void} */ @@ -4100,8 +4106,8 @@ module.exports = { "tags": [ "headings", "atx", "spaces" ], "parser": "none", "function": function MD018(params, onError) { - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - if (!inCode && + forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => { + if (!inCode && !inHTML && /^#+[^# \t]/.test(line) && !/#\s*$/.test(line) && !line.startsWith("#️⃣")) { diff --git a/helpers/helpers.js b/helpers/helpers.js index 114af4106..acfb7c370 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -365,7 +365,7 @@ module.exports.filterTokens = filterTokens; */ function getLineMetadata(params) { const lineMetadata = params.lines.map( - (line, index) => [ line, index, false, 0, false, false, false ] + (line, index) => [ line, index, false, 0, false, false, false, false ] ); filterTokens(params, "fence", (token) => { lineMetadata[token.map[0]][3] = 1; @@ -379,11 +379,6 @@ function getLineMetadata(params) { lineMetadata[i][2] = true; } }); - filterTokens(params, "html_block", (token) => { - for (let i = token.map[0]; i < token.map[1]; i++) { - lineMetadata[i][2] = true; - } - }); filterTokens(params, "table_open", (token) => { for (let i = token.map[0]; i < token.map[1]; i++) { lineMetadata[i][4] = true; @@ -399,6 +394,11 @@ function getLineMetadata(params) { filterTokens(params, "hr", (token) => { lineMetadata[token.map[0]][6] = true; }); + filterTokens(params, "html_block", (token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][7] = true; + } + }); return lineMetadata; } module.exports.getLineMetadata = getLineMetadata; @@ -412,6 +412,7 @@ module.exports.getLineMetadata = getLineMetadata; * @param {boolean} inTable Iff in a table. * @param {boolean} inItem Iff in a list item. * @param {boolean} inBreak Iff in semantic break. + * @param {boolean} inHTML Iff in HTML. * @returns {void} */ diff --git a/lib/md018.js b/lib/md018.js index 007c227af..b97f31cc4 100644 --- a/lib/md018.js +++ b/lib/md018.js @@ -13,8 +13,8 @@ module.exports = { "tags": [ "headings", "atx", "spaces" ], "parser": "none", "function": function MD018(params, onError) { - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - if (!inCode && + forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => { + if (!inCode && !inHTML && /^#+[^# \t]/.test(line) && !/#\s*$/.test(line) && !line.startsWith("#️⃣")) { diff --git a/test/ignore-html-block.md b/test/ignore-html-block.md new file mode 100644 index 000000000..5d3444fe3 --- /dev/null +++ b/test/ignore-html-block.md @@ -0,0 +1,9 @@ +# ignore-html-block.md + +## Title + +##Title2 {MD018} + + diff --git a/test/snapshots/markdownlint-test-scenarios.js.snap b/test/snapshots/markdownlint-test-scenarios.js.snap index feb1b50fd..d4d1145fc 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.js.snap and b/test/snapshots/markdownlint-test-scenarios.js.snap differ