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}
*/
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) {

View file

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