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): skip EPUB passages hidden by important inline styles (#4… · pingdotgg/t3code@4bc38b1

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
+33-2Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ function isXhtmlElement(
163163
);
164164
}
165165

166+
function hasImportantDisplayNone(style: string): boolean {
167+
// Stylesheet rules can override non-important inline display.
168+
if (!style || style.includes("\\") || !/display/i.test(style) || !/important/i.test(style))
169+
return false;
170+
let badString = false;
171+
const declarations = style.replaceAll(
172+
/\/\*[\s\S]*?(?:\*\/|$)|"[^"]*(?:"|$)|'[^']*(?:'|$)/g,
173+
(token) => {
174+
if (token.startsWith("/")) return " ";
175+
// CSS ends a string at a newline, so later declarations can still apply.
176+
if (/[\n\r\f]/.test(token)) badString = true;
177+
return '""';
178+
},
179+
);
180+
// Semicolons in blocks can be part of a declaration's value.
181+
if (badString || /[()[\]{}]/.test(declarations)) return false;
182+
let hidden = false;
183+
for (const [declaration] of declarations.matchAll(/[^;]+/g)) {
184+
const match =
185+
/^[\t\n\f\r ]*(display|all)[\t\n\f\r ]*:([^!]+)![\t\n\f\r ]*important[\t\n\f\r ]*$/i.exec(
186+
declaration,
187+
);
188+
if (!match) continue;
189+
const [, property, value] = match;
190+
if (!value?.trim()) continue;
191+
hidden = property?.toLowerCase() === "display" && /^[\t\n\f\r ]*none[\t\n\f\r ]*$/i.test(value);
192+
}
193+
return hidden;
194+
}
195+
166196
function xml(source: string, extension: string): XmlNode {
167197
const odf = [".odt", ".ods", ".odp"].includes(extension);
168198
const root: XmlNode = { name: "root", attrs: {}, children: [] };
@@ -255,8 +285,9 @@ function xml(source: string, extension: string): XmlNode {
255285
isXhtmlElement(tag.name, [...stack, node], rootTagName)) ||
256286
(extension === ".epub" &&
257287
(stack[1] ?? node).name === "html" &&
258-
Object.hasOwn(tag.attributes, "hidden") &&
259-
!/^until-found$/i.test(String(tag.attributes.hidden))) ||
288+
((Object.hasOwn(tag.attributes, "hidden") &&
289+
!/^until-found$/i.test(String(tag.attributes.hidden))) ||
290+
hasImportantDisplayNone(tag.attributes.style ?? ""))) ||
260291
(extension === ".docx" && node.name === "del") ||
261292
(extension === ".docx" &&
262293
node.name === "r" &&
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,18 @@ describe("question answer paths", () => {
19841984
'<!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>' +
19851985
"<ol><li>Indented\n <ul><li>Alpha</li></ul></li></ol>" +
19861986
'<div>Board<template><h2>Sample berth</h2><img alt="Sample map"/></template> now.</div>' +
1987-
"<p>Keep <template>Example sailing at dawn.</template>reading.</p></body></html>",
1987+
"<p>Keep <template>Example sailing at dawn.</template>reading.</p>" +
1988+
"<style>.published{display:block!important}</style>" +
1989+
'<p style="display:none!important; display:block!important">Service charge: $700.</p>' +
1990+
'<div style="DISPLAY: /* draft */ none ! important; display:block"><p>Cancelled surcharge: $500.</p><img alt="Hidden invoice illustration"/></div>' +
1991+
'<p>Review <span style="display:none!important">the retired version of </span>this invoice.</p>' +
1992+
'<p style="display:block !important; display:none">Total due: $700.</p>' +
1993+
'<p class="published" style="display:none">Bank transfer accepted.</p>' +
1994+
'<p style="--label: &quot;example;display:none!important;&quot;">Payment due tomorrow.</p>' +
1995+
'<p style="--options: {label: draft; display:none!important;};">Payment instructions.</p>' +
1996+
'<p style="--options:[);display:none!important">Accounts contact.</p>' +
1997+
'<p style="display:none!important;--label:&quot;draft&#10;;display:block!important">Visible total: $700.</p>' +
1998+
'<img alt="Hidden old payment instructions" style="--label:old\\ payment;display:none"/></body></html>',
19881999
"OEBPS/c.xhtml": '<html hidden=""><body><p>Root hidden</p></body></html>',
19892000
"OEBPS/d.xhtml":
19902001
'<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"><xh:body><xh:p>Start <template>Visible excerpt</template>' +
@@ -2009,6 +2020,8 @@ describe("question answer paths", () => {
20092020
"Before landing\nCollect bags",
20102021
"Indented\n Alpha",
20112022
"Board now.\nKeep reading.",
2023+
"Service charge: $700.\nReview this invoice.\nTotal due: $700.",
2024+
"Bank transfer accepted.\nPayment due tomorrow.\nPayment instructions.\nAccounts contact.\nVisible total: $700.",
20122025
"## Chapter 2",
20132026
"Last chapter",
20142027
"Totals\nTable 1: Revenue\nQ1\tQ2\n100\t200",
@@ -2031,6 +2044,9 @@ describe("question answer paths", () => {
20312044
"Sample berth",
20322045
"Sample map",
20332046
"Example sailing at dawn.",
2047+
"Cancelled surcharge",
2048+
"Hidden invoice illustration",
2049+
"Hidden old payment instructions",
20342050
"Hidden excerpt",
20352051
],
20362052
},

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.