Tokens inside tables that lack a map should get it from the surrounding table row (which is more scoped than the table body) (fixes #463).

This commit is contained in:
David Anson 2021-11-26 04:26:15 +00:00 committed by GitHub
parent 1e82f76596
commit 11806dc5cb
6 changed files with 106 additions and 34 deletions

View file

@ -181,27 +181,16 @@ function removeFrontMatter(content, frontMatter) {
* @returns {void}
*/
function annotateTokens(tokens, lines) {
let tableMap = null;
let trMap = null;
tokens.forEach(function forToken(token) {
// Handle missing maps for table head/body
if (
(token.type === "thead_open") ||
(token.type === "tbody_open")
) {
tableMap = [ ...token.map ];
} else if (
(token.type === "tr_close") &&
tableMap
) {
tableMap[0]++;
} else if (
(token.type === "thead_close") ||
(token.type === "tbody_close")
) {
tableMap = null;
// Provide missing maps for table content
if (token.type === "tr_open") {
trMap = token.map;
} else if (token.type === "tr_close") {
trMap = null;
}
if (tableMap && !token.map) {
token.map = [ ...tableMap ];
if (!token.map && trMap) {
token.map = [ ...trMap ];
}
// Update token metadata
if (token.map) {