Handle missing token.map for th_open tokens (breaking) change in markdown-it v12.

This commit is contained in:
David Anson 2020-11-24 13:01:19 -08:00
parent 77594dbf77
commit 85563c3e63
2 changed files with 26 additions and 10 deletions

View file

@ -176,18 +176,27 @@ function removeFrontMatter(content, frontMatter) {
* @returns {void} * @returns {void}
*/ */
function annotateTokens(tokens, lines) { function annotateTokens(tokens, lines) {
let tbodyMap = null; let tableMap = null;
tokens.forEach(function forToken(token) { tokens.forEach(function forToken(token) {
// Handle missing maps for table body // Handle missing maps for table head/body
if (token.type === "tbody_open") { if (
tbodyMap = token.map.slice(); (token.type === "thead_open") ||
} else if ((token.type === "tr_close") && tbodyMap) { (token.type === "tbody_open")
tbodyMap[0]++; ) {
} else if (token.type === "tbody_close") { tableMap = token.map.slice();
tbodyMap = null; } 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) { if (tableMap && !token.map) {
token.map = tbodyMap.slice(); token.map = tableMap.slice();
} }
// Update token metadata // Update token metadata
if (token.map) { if (token.map) {

View file

@ -0,0 +1,7 @@
# table-issue-with-markdown-it-12
| `CLIEngine` | `ESLint` |
| :------------------------------------------- | :--------------------------------- |
| `executeOnFiles(patterns)` | `lintFiles(patterns)` |
<!-- markdownlint-disable-file MD013 -->