GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): preserve image descriptions in EPUB attachment text (#42… · patroza/t3code@3b827b4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/provider
    • documentTextWorker.ts
    • userInputAttachments.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/provider/documentTextWorker.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/documentTextWorker.ts
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ function xml(source: string, extension: string): XmlNode {
165165
if (extension === ".epub" && node.name === "ruby" && stack[1]?.name === "html")
166166
separateRubyReadings(node);
167167
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+
}
168181
if (HIDDEN.has(node.name) || (!node.hasText && node.name !== "noBreakHyphen")) return;
169182
parent.hasText = true;
170183
if (node.name === "Choice") parent.hasTextChoice = true;
Collapse file

‎apps/server/src/provider/userInputAttachments.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,14 +1497,16 @@ describe("question answer paths", () => {
14971497
"OEBPS/a.xhtml":
14981498
'<!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>',
14991499
"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 &amp; 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>' +
15011501
"<ol><li>Indented\n <ul><li>Alpha</li></ul></li></ol></body></html>",
15021502
"OEBPS/c.xhtml": '<html hidden=""><body><p>Root hidden</p></body></html>',
15031503
},
15041504
expected: [
15051505
"## Chapter 1",
15061506
"\n# First chapter",
15071507
"Larkspur",
1508+
"Map: North & south piers open.",
1509+
"Cover art",
15081510
"Direct div",
15091511
"Direct section",
15101512
"Direct item emphasis trailing",
@@ -1529,6 +1531,9 @@ describe("question answer paths", () => {
15291531
"Draft note",
15301532
"Hidden block",
15311533
"Hidden nested",
1534+
"Hidden image text",
1535+
"Display none image",
1536+
"Invisible image",
15321537
"Root hidden",
15331538
],
15341539
},

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.