From 2e391a5ca1c93bfe448876fc2a7c8e2bb5e93a03 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 23 May 2019 14:49:55 +0200 Subject: [PATCH] Allow trailing spaces in code blocks --- lib/md009.js | 6 ++++-- test/code_block_fenced.md | 7 +++++++ test/code_block_indented.md | 6 +++++- test/trailing_spaces_br.md | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/md009.js b/lib/md009.js index 18add32e..dfe9c59b 100644 --- a/lib/md009.js +++ b/lib/md009.js @@ -30,9 +30,11 @@ module.exports = { listItemLineNumbers.sort((a, b) => a - b); } const expected = (brSpaces < 2) ? 0 : brSpaces; - forEachLine(lineMetadata(), (line, lineIndex) => { + let inFencedCode = 0; + forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { + inFencedCode += onFence; const lineNumber = lineIndex + 1; - if (trailingSpaceRe.test(line) && + if ((!inCode || inFencedCode !== 0) && trailingSpaceRe.test(line) && !includesSorted(listItemLineNumbers, lineNumber)) { const actual = line.length - line.trimRight().length; if (expected !== actual) { diff --git a/test/code_block_fenced.md b/test/code_block_fenced.md index 4c05b627..c893670e 100644 --- a/test/code_block_fenced.md +++ b/test/code_block_fenced.md @@ -9,9 +9,16 @@ And here is more text This is a code block that won't trigger. ``` +```text +This is code + +with an empty line. +``` + But we'll do another: And this {MD046} will. Final text is here +{MD009:14} diff --git a/test/code_block_indented.md b/test/code_block_indented.md index ae443f7e..5576dcd8 100644 --- a/test/code_block_indented.md +++ b/test/code_block_indented.md @@ -14,4 +14,8 @@ But we'll do another: And this will. -Final text is here +One last one: + + This is code + + with an empty indented line. diff --git a/test/trailing_spaces_br.md b/test/trailing_spaces_br.md index a619772b..861de197 100644 --- a/test/trailing_spaces_br.md +++ b/test/trailing_spaces_br.md @@ -1,4 +1,6 @@ This line has a single trailing space {MD009} This line has two trailing spaces and should be allowed This line has three trailing spaces {MD009} + +{MD009:4} This line has four trailing spaces {MD009}