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.