mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
fix(import): keep table rows together
Tables were flattened to one paragraph per cell, losing row grouping. Join each row's cells into a single paragraph so the row structure survives (the model has no table node). Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk
This commit is contained in:
1 parent
f4079a6f54
commit
983d8fd2c0
1 file changed
+19
@@ -195,6 +195,23 @@ function listItems(el: Element): JSONContent[] {
|
||||
return items;
|
||||
}
|
||||
|
||||
function tableBlocks(el: Element): JSONContent[] {
|
||||
const out: JSONContent[] = [];
|
||||
Array.from(el.querySelectorAll("tr")).forEach((tr) => {
|
||||
const content: JSONContent[] = [];
|
||||
Array.from(tr.children)
|
||||
.filter((c) => c.localName.toLowerCase() === "td" || c.localName.toLowerCase() === "th")
|
||||
.forEach((cell) => {
|
||||
const inline = inlineOf(cell);
|
||||
if (!meaningful(inline)) return;
|
||||
if (content.length) content.push({ type: "text", text: " · " });
|
||||
content.push(...inline);
|
||||
});
|
||||
if (meaningful(content)) out.push({ type: "paragraph", content });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
function blockFromElement(el: Element): JSONContent[] {
|
||||
const tag = el.localName.toLowerCase();
|
||||
switch (tag) {
|
||||
@@ -230,6 +247,8 @@ function blockFromElement(el: Element): JSONContent[] {
|
||||
return imgFigure(el);
|
||||
case "svg":
|
||||
return svgFigure(el);
|
||||
case "table":
|
||||
return tableBlocks(el);
|
||||
case "script":
|
||||
case "style":
|
||||
return [];
|
||||
|
||||
Reference in new issue
Block a user