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 DOCX hyphen semantics · pingdotgg/t3code@c232b98

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
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ interface XmlNode {
4141
hasTextChoice?: boolean;
4242
}
4343

44-
function xml(source: string, odfSpaces = false, htmlEntities = false): XmlNode {
44+
function xml(source: string, extension: string): XmlNode {
4545
const root: XmlNode = { name: "root", attrs: {}, children: [] };
4646
const stack = [root];
4747
let nodes = 0;
4848
const parser = new SaxesParser();
49-
if (htmlEntities) Object.assign(parser.ENTITIES, characterEntities);
49+
if (extension === ".epub") Object.assign(parser.ENTITIES, characterEntities);
5050
parser.on("opentag", (tag) => {
5151
if (++nodes > 200_000 || stack.length > 128) throw new Truncation("XML structure limit");
5252
const node: XmlNode = {
@@ -59,20 +59,25 @@ function xml(source: string, odfSpaces = false, htmlEntities = false): XmlNode {
5959
),
6060
children: [],
6161
};
62-
if (odfSpaces && node.name === "s") node.spaceCount = repeatCount(node.attrs.c);
62+
if ([".odt", ".ods", ".odp"].includes(extension) && node.name === "s")
63+
node.spaceCount = repeatCount(node.attrs.c);
6364
stack.at(-1)!.children.push(node);
6465
stack.push(node);
6566
});
6667
parser.on("closetag", () => {
6768
const node = stack.pop()!;
6869
const parent = stack.at(-1)!;
70+
if (extension === ".docx" && node.name === "del") {
71+
parent.children.pop();
72+
return;
73+
}
6974
// Markup-compatibility fallbacks repeat their mc:Choice content, e.g. Word text boxes.
7075
// Keep one when no Choice carries text, such as a chart with a VML caption.
7176
if (node.name === "Fallback" && parent.hasTextChoice) {
7277
parent.children.pop();
7378
return;
7479
}
75-
if (!node.hasText) return;
80+
if (!node.hasText && node.name !== "noBreakHyphen") return;
7681
parent.hasText = true;
7782
if (node.name === "Choice") parent.hasTextChoice = true;
7883
});
@@ -165,7 +170,7 @@ function odfValue(cell: XmlNode): string {
165170
}
166171
}
167172
function hasCellText(cell: XmlNode): boolean {
168-
if (odfValue(cell).trim()) return true;
173+
if (odfValue(cell).trim() || cell.name === "noBreakHyphen") return true;
169174
// Space markers can have enormous repeat counts; emptiness never requires expanding them.
170175
if (HIDDEN.has(cell.name) || cell.spaceCount !== undefined) return false;
171176
return cell.children.some((child) =>
@@ -442,7 +447,7 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
442447
try {
443448
const data = files.get(name);
444449
if (!data) throw new Error("Missing document part");
445-
return xml(data, [".odt", ".ods", ".odp"].includes(extension), extension === ".epub");
450+
return xml(data, extension);
446451
} catch (error) {
447452
if (error instanceof Truncation) throw error;
448453
skip(name);
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/userInputAttachments.test.ts
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,28 +695,32 @@ describe("question answer paths", () => {
695695
bounded: true,
696696
parts: {
697697
"word/document.xml":
698-
'<w:document xmlns:w="urn:w"><w:body><w:p><w:pPr><w:pStyle w:val="Heading2"/></w:pPr><w:r><w:t>Report &amp; totals</w:t></w:r></w:p><w:tbl><w:tr><w:tc><w:p><w:r><w:t>North</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>12</w:t></w:r></w:p><w:p><w:r><w:t>34</w:t></w:r></w:p></w:tc></w:tr><w:tr><w:tc><w:p><w:r><w:t>Before</w:t></w:r></w:p><w:tbl><w:tr><w:tc><w:p><w:r><w:t>Inner</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p><w:r><w:t>After</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>Neighbor</w:t></w:r></w:p></w:tc></w:tr></w:tbl></w:body></w:document>',
698+
'<w:document xmlns:w="urn:w"><w:body><w:p><w:pPr><w:pStyle w:val="Heading2"/></w:pPr><w:r><w:t>Report &amp; totals</w:t></w:r></w:p><w:tbl><w:tr><w:tc><w:p><w:r><w:t>North</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>12</w:t></w:r></w:p><w:p><w:r><w:t>34</w:t></w:r></w:p></w:tc></w:tr><w:tr><w:tc><w:p><w:r><w:t>Before</w:t></w:r></w:p><w:tbl><w:tr><w:tc><w:p><w:r><w:t>Inner</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p><w:r><w:t>After</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>Neighbor</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:noBreakHyphen/></w:r></w:p></w:tc></w:tr><w:tr><w:tc><w:p><w:r><w:noBreakHyphen/></w:r></w:p></w:tc></w:tr></w:tbl></w:body></w:document>',
699699
},
700-
expected: ["## Report & totals", "North\t12 34", "Before Inner After\tNeighbor"],
700+
expected: [
701+
"## Report & totals",
702+
"North\t12 34",
703+
"Before Inner After\tNeighbor\t\u2011\n\u2011",
704+
],
701705
},
702706
{
703707
ext: "docx",
704708
bounded: true,
705709
parts: {
706710
"word/document.xml":
707-
'<w:document xmlns:w="urn:w"><w:body><w:p><w:r><w:t>First</w:t><w:cr/><w:t>Second</w:t><w:br/><w:t>Third</w:t><w:noBreakHyphen/><w:t>party</w:t></w:r></w:p></w:body></w:document>',
711+
'<w:document xmlns:w="urn:w"><w:body><w:p><w:r><w:t>First</w:t><w:cr/><w:t>Second</w:t><w:br/><w:t>Third</w:t><w:noBreakHyphen/><w:t>party</w:t><mc:AlternateContent xmlns:mc="urn:mc"><mc:Choice Requires="w"><w:noBreakHyphen/></mc:Choice><mc:Fallback><w:t>‑</w:t></mc:Fallback></mc:AlternateContent><w:t>End</w:t></w:r></w:p></w:body></w:document>',
708712
},
709-
expected: ["First\nSecond\nThird\u2011party"],
713+
expected: ["First\nSecond\nThird\u2011party\u2011End"],
710714
},
711715
{
712716
ext: "docx",
713717
bounded: true,
714718
parts: {
715719
"word/document.xml":
716-
'<w:document xmlns:w="urn:w"><w:body><w:p><w:r><w:t>Intro</w:t></w:r><w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText> PAGEREF _Toc1 \\h </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r><w:r><w:t> 3</w:t></w:r><w:r><w:fldChar w:fldCharType="end"/></w:r></w:p><w:p><w:pPr><w:tabs><w:tab w:val="right" w:pos="9350"/></w:tabs></w:pPr><w:r><w:t xml:space="preserve">Fee </w:t></w:r><w:del><w:r><w:delText>$500</w:delText></w:r></w:del><w:ins><w:r><w:t>$700</w:t></w:r></w:ins><w:moveFrom><w:r><w:t>Moved</w:t></w:r></w:moveFrom><w:r><w:tab/><w:t>due</w:t></w:r></w:p></w:body></w:document>',
720+
'<w:document xmlns:w="urn:w"><w:body><w:p><w:r><w:t>Intro</w:t></w:r><w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText> PAGEREF _Toc1 \\h </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r><w:r><w:t> 3</w:t></w:r><w:r><w:fldChar w:fldCharType="end"/></w:r></w:p><w:p><w:pPr><w:tabs><w:tab w:val="right" w:pos="9350"/></w:tabs></w:pPr><w:r><w:t xml:space="preserve">Fee </w:t></w:r><w:del><w:r><w:delText>$500</w:delText><w:noBreakHyphen/></w:r></w:del><w:ins><w:r><w:t>$700</w:t></w:r></w:ins><w:moveFrom><w:r><w:t>Moved</w:t></w:r></w:moveFrom><w:r><w:tab/><w:t>due</w:t></w:r></w:p></w:body></w:document>',
717721
},
718722
expected: ["Intro 3\nFee $700\tdue"],
719-
absent: ["PAGEREF", "$500", "Moved"],
723+
absent: ["PAGEREF", "$500", "Moved", "\u2011"],
720724
},
721725
{
722726
ext: "odt",
@@ -1042,7 +1046,7 @@ describe("question answer paths", () => {
10421046
"OEBPS/book.opf":
10431047
'<package><manifest><item id="a" href="a.xhtml"/><item id="b" href="b.xhtml"/></manifest><spine><itemref idref="b"/><itemref idref="a"/></spine></package>',
10441048
"OEBPS/a.xhtml":
1045-
'<!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</p></body></html>',
1049+
'<!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></body></html>',
10461050
"OEBPS/b.xhtml":
10471051
"<!DOCTYPE html><html><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></body></html>",
10481052
},
@@ -1059,7 +1063,7 @@ describe("question answer paths", () => {
10591063
"Before Inner After\tNeighbor",
10601064
"## Chapter 2",
10611065
"Last chapter",
1062-
"Price 10 8",
1066+
"Price 10 8 old",
10631067
],
10641068
},
10651069
];

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.