From 3e753636cfc264c964668488a671038d49b79570 Mon Sep 17 00:00:00 2001 From: David Anson Date: Wed, 13 Feb 2019 19:52:34 -0800 Subject: [PATCH] Handle case where token map extends beyond last line of input (fixes #166). --- lib/markdownlint.js | 2 +- test/markdownlint-test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/markdownlint.js b/lib/markdownlint.js index 27cb1ebd..1a5391d7 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -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 diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index cadf5ec9..7146bba6 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -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(); + }); + };