Handle case where token map extends beyond last line of input (fixes #166).

This commit is contained in:
David Anson 2019-02-13 19:52:34 -08:00
parent 90bd0810e7
commit 3e753636cf
2 changed files with 30 additions and 1 deletions

View file

@ -164,7 +164,7 @@ function annotateTokens(tokens, lines) {
token.line = lines[token.map[0]];
token.lineNumber = token.map[0] + 1;
// Trim bottom of token to exclude whitespace lines
while (token.map[1] && !(lines[token.map[1] - 1].trim())) {
while (token.map[1] && !((lines[token.map[1] - 1] || "").trim())) {
token.map[1]--;
}
// Annotate children with lineNumber

View file

@ -2628,3 +2628,32 @@ module.exports.markdownItPluginsMathjax =
test.done();
});
};
module.exports.markdownItPluginsMathjaxIssue166 =
function markdownItPluginsMathjaxIssue166(test) {
test.expect(2);
markdownlint({
"strings": {
"string":
`## Heading
$$
1
$$$$
2
$$`
},
"markdownItPlugins": [ [ pluginKatex ] ],
"resultVersion": 0
}, function callback(err, actual) {
test.ifError(err);
const expected = {
"string": {
"MD002": [ 1 ],
"MD041": [ 1 ]
}
};
test.deepEqual(actual, expected, "Unexpected issues.");
test.done();
});
};