GeezerVison is showing github.com — fix(server): preserve image descriptions in EPUB attachment text (#42… · patroza/t3code@3b827b4
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 +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -165,6 +165,19 @@ function xml(source: string, extension: string): XmlNode { | 165 | 165 | if (extension === ".epub" && node.name === "ruby" && stack[1]?.name === "html") | 166 | 166 | separateRubyReadings(node); | 167 | 167 | if (node.name === "Fallback" && !retainCompatibilityFallback(parent, node)) return; | | 168 | + const alt = tag.attributes.alt; | | 169 | + if ( | | 170 | + extension === ".epub" && | | 171 | + node.name === "img" && | | 172 | + stack[1]?.name === "html" && | | 173 | + alt?.trim() && | | 174 | + !/(?:^|;)\s*(?:display\s*:\s*none|visibility\s*:\s*(?:hidden|collapse))\s*(?:!important\s*)?(?:;|$)/i.test( | | 175 | + String(tag.attributes.style ?? ""), | | 176 | + ) | | 177 | + ) { | | 178 | + node.children.push(alt); | | 179 | + node.hasText = true; | | 180 | + } | 168 | 181 | if (HIDDEN.has(node.name) || (!node.hasText && node.name !== "noBreakHyphen")) return; | 169 | 182 | parent.hasText = true; | 170 | 183 | if (node.name === "Choice") parent.hasTextChoice = true; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1497,14 +1497,16 @@ describe("question answer paths", () => { | 1497 | 1497 | "OEBPS/a.xhtml": | 1498 | 1498 | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><body><p>Last chapter</p><p>Price <s>10</s> 8 <del>old</del></p><p><ruby>山路<rt>やまみち</rt></ruby>を歩く。<ruby>東京<rp>(</rp><script type="application/json">{}</script><rt>とうきょう</rt><script type="application/json">{}</script><rp>)</rp></ruby>に着く。<ruby>川<rt/></ruby>を見る。<ruby>海<rp/><rt>うみ</rt><rp> </rp></ruby>まで。</p></body></html>', | 1499 | 1499 | "OEBPS/b.xhtml": | 1500 | | - '<!DOCTYPE html><html><head><title>My Novel</title><meta name="author" content="Hidden Author"/></head><body><h1>First chapter</h1><p>Larkspur</p><div>Direct div<section>Direct section<li>Direct item <em>emphasis</em> trailing</li></section></div><div>Account: A<br/>Balance: 731<line-break/>Currency: USD</div><table><thead><tr><th>Heading</th><th>Total</th></tr></thead><tbody><tr><td>Important value</td><td>731</td></tr><tr><td>Before<table><tr><td>Inner</td></tr></table>After</td><td>Neighbor</td></tr></tbody></table><dl><dt>Port</dt><dd>443</dd><dt>Timeout</dt><dd>30 seconds</dd></dl><p hidden="">Draft note</p><div hidden="hidden">Hidden block<p>Hidden nested</p></div><p hidden="UNTIL-FOUND">Findable note</p><p aria-hidden="true">Decorative note</p><p x:hidden="true">Prefixed note</p><ol><li>Before boarding<ul><li>Check passports<ol><li>Compare names</li></ol></li><li>Confirm gate</li></ul></li><li>Board promptly</li><li><p>Before landing</p><ul><li>Collect bags</li></ul></li></ol>' + | | 1500 | + '<!DOCTYPE html><html><head><title>My Novel</title><meta name="author" content="Hidden Author"/></head><body><h1>First chapter</h1><p>Larkspur</p><p>Map: <img src="map.png" alt="North & south piers"/> open<img src="blank.png" alt=""/><img src="missing.png"/>.</p><div><img src="cover.png" alt="Cover art"/></div><img hidden="" src="draft.png" alt="Hidden image text"/><img src="none.png" alt="Display none image" style="width: 1em; DISPLAY: none"/><img src="invisible.png" alt="Invisible image" style="visibility:hidden !important"/><div>Direct div<section>Direct section<li>Direct item <em>emphasis</em> trailing</li></section></div><div>Account: A<br/>Balance: 731<line-break/>Currency: USD</div><table><thead><tr><th>Heading</th><th>Total</th></tr></thead><tbody><tr><td>Important value</td><td>731</td></tr><tr><td>Before<table><tr><td>Inner</td></tr></table>After</td><td>Neighbor</td></tr></tbody></table><dl><dt>Port</dt><dd>443</dd><dt>Timeout</dt><dd>30 seconds</dd></dl><p hidden="">Draft note</p><div hidden="hidden">Hidden block<p>Hidden nested</p></div><p hidden="UNTIL-FOUND">Findable note</p><p aria-hidden="true">Decorative note</p><p x:hidden="true">Prefixed note</p><ol><li>Before boarding<ul><li>Check passports<ol><li>Compare names</li></ol></li><li>Confirm gate</li></ul></li><li>Board promptly</li><li><p>Before landing</p><ul><li>Collect bags</li></ul></li></ol>' + | 1501 | 1501 | "<ol><li>Indented\n <ul><li>Alpha</li></ul></li></ol></body></html>", | 1502 | 1502 | "OEBPS/c.xhtml": '<html hidden=""><body><p>Root hidden</p></body></html>', | 1503 | 1503 | }, | 1504 | 1504 | expected: [ | 1505 | 1505 | "## Chapter 1", | 1506 | 1506 | "\n# First chapter", | 1507 | 1507 | "Larkspur", | | 1508 | + "Map: North & south piers open.", | | 1509 | + "Cover art", | 1508 | 1510 | "Direct div", | 1509 | 1511 | "Direct section", | 1510 | 1512 | "Direct item emphasis trailing", | @@ -1529,6 +1531,9 @@ describe("question answer paths", () => { | 1529 | 1531 | "Draft note", | 1530 | 1532 | "Hidden block", | 1531 | 1533 | "Hidden nested", | | 1534 | + "Hidden image text", | | 1535 | + "Display none image", | | 1536 | + "Invisible image", | 1532 | 1537 | "Root hidden", | 1533 | 1538 | ], | 1534 | 1539 | }, | |
|