1
0

Fix empty cell MD table render bug

This commit is contained in:
Zef Hemel 2022-11-30 15:59:41 +01:00
parent 15263a8dc6
commit 8c62ca981e

View File

@ -335,11 +335,33 @@ function render(
name: "td",
body: cleanTags(mapRender(t.children!)),
};
case "TableRow":
case "TableRow": {
const children = t.children!;
const newChildren: ParseTree[] = [];
// Ensure there is TableCell in between every delimiter
let lookingForCell = false;
for (const child of children) {
if (child.type === "TableDelimiter" && lookingForCell) {
// We were looking for a cell, but didn't fine one: empty cell!
// Let's inject an empty one
newChildren.push({
type: "TableCell",
children: [],
});
}
if (child.type === "TableDelimiter") {
lookingForCell = true;
}
if (child.type === "TableCell") {
lookingForCell = false;
}
newChildren.push(child);
}
return {
name: "tr",
body: cleanTags(mapRender(t.children!)),
body: cleanTags(mapRender(newChildren)),
};
}
// Text
case undefined:
return t.text!;