From 2ccacf03f56137821aa45bd93a42c1a302522993 Mon Sep 17 00:00:00 2001 From: David Anson Date: Mon, 4 Mar 2019 19:54:23 -0800 Subject: [PATCH] MD037 should try to ignore escaped emphasis markers (fixes #168). --- lib/md037.js | 17 ++++++++++------- test/escaped-emphasis-markers.md | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 test/escaped-emphasis-markers.md diff --git a/lib/md037.js b/lib/md037.js index ebf80868..44582381 100644 --- a/lib/md037.js +++ b/lib/md037.js @@ -11,18 +11,21 @@ module.exports = { "function": function MD037(params, onError) { shared.forEachInlineChild(params, "text", function forToken(token) { let left = true; - let match = /(?:^|\s)(\*\*?|__?)\s.+\1/.exec(token.content); + let match = /(?:^|\s)(\*\*?|__?)\s.*[^\\]\1/.exec(token.content); if (!match) { left = false; - match = /(\*\*?|__?).+\s\1(?:\s|$)/.exec(token.content); + match = /(?:^|[^\\])(\*\*?|__?).+\s\1(?:\s|$)/.exec(token.content); } if (match) { - const text = match[0].trim(); + const fullText = match[0]; const line = params.lines[token.lineNumber - 1]; - const column = line.indexOf(text) + 1; - const length = text.length; - shared.addErrorContext(onError, token.lineNumber, - text, left, !left, [ column, length ]); + if (line.indexOf(fullText) !== -1) { + const text = fullText.trim(); + const column = line.indexOf(text) + 1; + const length = text.length; + shared.addErrorContext(onError, token.lineNumber, + text, left, !left, [ column, length ]); + } } }); } diff --git a/test/escaped-emphasis-markers.md b/test/escaped-emphasis-markers.md new file mode 100644 index 00000000..319dc294 --- /dev/null +++ b/test/escaped-emphasis-markers.md @@ -0,0 +1,29 @@ +# Heading + +Escaped asterisks \* should \* be ignored by MD037. + +Escaped asterisks \* should * be ignored by MD037. + +Escaped asterisks * should \* be ignored by MD037. + +Escaped asterisks \** should ** be ignored by MD037. + +Escaped asterisks *\* should ** be ignored by MD037. + +Escaped asterisks ** should \** be ignored by MD037. + +Escaped asterisks ** should *\* be ignored by MD037. + +Escaped underscores \_ should \_ be ignored by MD037. + +Escaped underscores \_ should _ be ignored by MD037. + +Escaped underscores _ should \_ be ignored by MD037. + +Escaped underscores \__ should __ be ignored by MD037. + +Escaped underscores _\_ should __ be ignored by MD037. + +Escaped underscores __ should \__ be ignored by MD037. + +Escaped underscores __ should _\_ be ignored by MD037.