From 983d8fd2c0909c71e1aa37ad8c4a2ac64c8f3db3 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 22 Jun 2026 13:37:31 -0400 Subject: [PATCH] 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 --- src/import/epub.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/import/epub.ts b/src/import/epub.ts index ff2e29b..8b29f6a 100644 --- a/src/import/epub.ts +++ b/src/import/epub.ts @@ -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 [];