From a54e7a42ef271742f3a6c0b47de207a8a41c60d8 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 22 Jun 2026 13:36:07 -0400 Subject: [PATCH] fix(import): preserve link, underline, strike and code marks EPUB import only mapped bold and italic; a, u, s/del/strike and code elements lost their formatting (kept as plain text). Map them to the matching marks, consistent with what the exporters now render. Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk --- src/import/epub.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/import/epub.ts b/src/import/epub.ts index 8877acc..934a95b 100644 --- a/src/import/epub.ts +++ b/src/import/epub.ts @@ -9,7 +9,7 @@ export interface RawFile { encoding: "utf8" | "base64"; } -type Mark = { type: string }; +type Mark = { type: string; attrs?: Record }; const BLOCK_TAGS = new Set([ "p", "div", "section", "article", "main", "header", "footer", "aside", @@ -81,8 +81,8 @@ function hasMark(marks: Mark[], type: string): boolean { return marks.some((m) => m.type === type); } -function addMark(marks: Mark[], type: string): Mark[] { - return hasMark(marks, type) ? marks : [...marks, { type }]; +function addMark(marks: Mark[], type: string, attrs?: Record): Mark[] { + return hasMark(marks, type) ? marks : [...marks, attrs ? { type, attrs } : { type }]; } function collectInline(node: Node, marks: Mark[], out: JSONContent[]): void { @@ -102,6 +102,15 @@ function collectInline(node: Node, marks: Mark[], out: JSONContent[]): void { collectInline(el, addMark(marks, "bold"), out); } else if (tag === "em" || tag === "i") { collectInline(el, addMark(marks, "italic"), out); + } else if (tag === "u") { + collectInline(el, addMark(marks, "underline"), out); + } else if (tag === "s" || tag === "strike" || tag === "del") { + collectInline(el, addMark(marks, "strike"), out); + } else if (tag === "code") { + collectInline(el, addMark(marks, "code"), out); + } else if (tag === "a") { + const href = el.getAttribute("href"); + collectInline(el, href ? addMark(marks, "link", { href }) : marks, out); } else if (!BLOCK_TAGS.has(tag)) { collectInline(el, marks, out); }