From 85563c3e63859ad74cccbd1a075df39b1c2576ed Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 24 Nov 2020 13:01:19 -0800 Subject: [PATCH] Handle missing token.map for th_open tokens (breaking) change in markdown-it v12. --- lib/markdownlint.js | 29 ++++++++++++++++--------- test/table-issue-with-markdown-it-12.md | 7 ++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 test/table-issue-with-markdown-it-12.md diff --git a/lib/markdownlint.js b/lib/markdownlint.js index b64cf969..b881e03f 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -176,18 +176,27 @@ function removeFrontMatter(content, frontMatter) { * @returns {void} */ function annotateTokens(tokens, lines) { - let tbodyMap = null; + let tableMap = null; tokens.forEach(function forToken(token) { - // Handle missing maps for table body - if (token.type === "tbody_open") { - tbodyMap = token.map.slice(); - } else if ((token.type === "tr_close") && tbodyMap) { - tbodyMap[0]++; - } else if (token.type === "tbody_close") { - tbodyMap = null; + // Handle missing maps for table head/body + if ( + (token.type === "thead_open") || + (token.type === "tbody_open") + ) { + tableMap = token.map.slice(); + } else if ( + (token.type === "tr_close") && + tableMap + ) { + tableMap[0]++; + } else if ( + (token.type === "thead_close") || + (token.type === "tbody_close") + ) { + tableMap = null; } - if (tbodyMap && !token.map) { - token.map = tbodyMap.slice(); + if (tableMap && !token.map) { + token.map = tableMap.slice(); } // Update token metadata if (token.map) { diff --git a/test/table-issue-with-markdown-it-12.md b/test/table-issue-with-markdown-it-12.md new file mode 100644 index 00000000..b5e7d4fd --- /dev/null +++ b/test/table-issue-with-markdown-it-12.md @@ -0,0 +1,7 @@ +# table-issue-with-markdown-it-12 + +| `CLIEngine` | `ESLint` | +| :------------------------------------------- | :--------------------------------- | +| `executeOnFiles(patterns)` | `lintFiles(patterns)` | + +