GeezerVison is showing github.com — fix(server): separate wrapped EPUB nested lists from parent text (#43… · patroza/t3code@fbb6526
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/provider/documentTextWorker.ts +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,7 +323,10 @@ function* paragraphs(node: XmlNode): Generator<TextPart, void> { | 323 | 323 | yield* text(child); | 324 | 324 | yield "\n"; | 325 | 325 | } else { | 326 | | - if (node.name === "li" && ["ol", "ul"].includes(child.name)) yield LINE_START; | | 326 | + if (["ol", "ul", "dl"].includes(child.name)) { | | 327 | + if (!child.hasText) continue; | | 328 | + yield LINE_START; | | 329 | + } | 327 | 330 | yield* paragraphs(child); | 328 | 331 | if (["li", "div", "section", "dt", "dd"].includes(child.name)) yield "\n"; | 329 | 332 | } | @@ -1120,7 +1123,7 @@ export async function extractDocumentText(path: string, extension: string): Prom | 1120 | 1123 | continue; | 1121 | 1124 | } | 1122 | 1125 | if (part === LINE_START) { | 1123 | | - // A nested list starts its own line unless its parent item's text already ended one. | | 1126 | + // A list starts its own line unless the text before it already ended one. | 1124 | 1127 | if (!midLine) continue; | 1125 | 1128 | part = "\n"; | 1126 | 1129 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -649,6 +649,25 @@ describe("question answer paths", () => { | 649 | 649 | Effect.gen(function* () { | 650 | 650 | const config = yield* ServerConfig.ServerConfig; | 651 | 651 | const cases = [ | | 652 | + { | | 653 | + ext: "epub", | | 654 | + bounded: true, | | 655 | + parts: { | | 656 | + "META-INF/container.xml": '<container><rootfile full-path="book.opf"/></container>', | | 657 | + "book.opf": | | 658 | + '<package><manifest><item id="chapter" href="chapter.xhtml" media-type="application/xhtml+xml"/></manifest><spine><itemref idref="chapter"/></spine></package>', | | 659 | + "chapter.xhtml": | | 660 | + '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Guide</title></head><body><ol><li>Before boarding<div><ul><li>Check passports</li></ul></div></li></ol>Intro<ul><li>Read the checklist</li></ul><dl><dt>Visa</dt><dd>Requirements<ul><li>Photo</li></ul></dd></dl><div>Carry<dl><dt>Passport</dt><dd>Required</dd></dl></div><div>Leave <ul></ul>room</div><div>Keep <ul><li hidden="">Draft</li></ul>walking</div></body></html>', | | 661 | + }, | | 662 | + expected: [ | | 663 | + "Before boarding\nCheck passports", | | 664 | + "Intro\nRead the checklist", | | 665 | + "Requirements\nPhoto", | | 666 | + "Carry\nPassport\nRequired", | | 667 | + "Leave room", | | 668 | + "Keep walking", | | 669 | + ], | | 670 | + }, | 652 | 671 | { | 653 | 672 | ext: "epub", | 654 | 673 | bounded: true, | |
|