Update annotateTokens to handle multi-line code spans.

This commit is contained in:
David Anson 2019-09-27 21:18:16 -07:00
parent 3632ce28b9
commit 40ac584482
2 changed files with 20 additions and 0 deletions

View file

@ -172,11 +172,20 @@ function annotateTokens(tokens, lines) {
}
// Annotate children with lineNumber
let lineNumber = token.lineNumber;
const codeSpanExtraLines = [];
helpers.forEachInlineCodeSpan(
token.content,
function handleInlineCodeSpan(code) {
codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1);
}
);
(token.children || []).forEach(function forChild(child) {
child.lineNumber = lineNumber;
child.line = lines[lineNumber - 1];
if ((child.type === "softbreak") || (child.type === "hardbreak")) {
lineNumber++;
} else if (child.type === "code_inline") {
lineNumber += codeSpanExtraLines.shift();
}
});
}

View file

@ -11,3 +11,14 @@ the (same text)[https://www.example.com/two]. {MD011} {MD034}
<!-- markdownlint-disable line-length -->
Two (issues)[https://www.example.com/three] on the (same line)[https://www.example.com/four]. {MD011} {MD034}
`code code
code`
(reversed)[link] {MD011}
text
text `code
code code
code` text
text
text (reversed)[link] text {MD011}