MD037 should try to ignore escaped emphasis markers (fixes #168).

This commit is contained in:
David Anson 2019-03-04 19:54:23 -08:00
parent dd3bd3d7ee
commit 2ccacf03f5
2 changed files with 39 additions and 7 deletions

View file

@ -11,19 +11,22 @@ module.exports = {
"function": function MD037(params, onError) { "function": function MD037(params, onError) {
shared.forEachInlineChild(params, "text", function forToken(token) { shared.forEachInlineChild(params, "text", function forToken(token) {
let left = true; let left = true;
let match = /(?:^|\s)(\*\*?|__?)\s.+\1/.exec(token.content); let match = /(?:^|\s)(\*\*?|__?)\s.*[^\\]\1/.exec(token.content);
if (!match) { if (!match) {
left = false; left = false;
match = /(\*\*?|__?).+\s\1(?:\s|$)/.exec(token.content); match = /(?:^|[^\\])(\*\*?|__?).+\s\1(?:\s|$)/.exec(token.content);
} }
if (match) { if (match) {
const text = match[0].trim(); const fullText = match[0];
const line = params.lines[token.lineNumber - 1]; const line = params.lines[token.lineNumber - 1];
if (line.indexOf(fullText) !== -1) {
const text = fullText.trim();
const column = line.indexOf(text) + 1; const column = line.indexOf(text) + 1;
const length = text.length; const length = text.length;
shared.addErrorContext(onError, token.lineNumber, shared.addErrorContext(onError, token.lineNumber,
text, left, !left, [ column, length ]); text, left, !left, [ column, length ]);
} }
}
}); });
} }
}; };

View file

@ -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.