GeezerVison is showing github.com — fix(server): DOCX merged table cells no longer shift later columns in… · patroza/t3code@b136053
File tree
Expand 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 +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -366,11 +366,18 @@ function* table(node: XmlNode): Generator<TextPart, void> { |
366 | 366 | for (let index = 0; index < repeat; index++) { |
367 | 367 | if (++rowCount > 10_000) throw new Truncation("Row limit"); |
368 | 368 | let column = 0; |
| 369 | + let gap = 0; |
369 | 370 | for (const cell of cells) { |
370 | 371 | const count = repeatCount(cell.attrs["number-columns-repeated"]); |
| 372 | + // Word emits no cell for columns covered by w:gridSpan; pad before the next cell. |
| 373 | + const tcPr = cell.name === "tc" ? children(cell).find((c) => c.name === "tcPr") : undefined; |
| 374 | + const val = tcPr && children(tcPr).find((c) => c.name === "gridSpan")?.attrs.val; |
| 375 | + const span = val ? Math.max(1, Number.parseInt(val, 10) || 1) : 1; |
371 | 376 | for (let i = 0; i < count; i++) { |
372 | | - if (column >= 512) throw new Truncation("Column limit"); |
373 | | - if (column++) yield "\t"; |
| 377 | + column += span; |
| 378 | + if (column > 512) throw new Truncation("Column limit"); |
| 379 | + if (gap) yield "\t".repeat(gap); |
| 380 | + gap = span; |
374 | 381 | // LibreOffice hides the contents a merge covers; the cell still holds its column. |
375 | 382 | if (covered(cell)) continue; |
376 | 383 | yield CELL_START; |
|
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 |
|---|
@@ -961,6 +961,25 @@ describe("question answer paths", () => { |
961 | 961 | "Before Inner After\tNeighbor\t\u2011\n\u2011\nDemoted\nIntro. # Box title", |
962 | 962 | ], |
963 | 963 | }, |
| 964 | + { |
| 965 | + ext: "docx", |
| 966 | + bounded: true, |
| 967 | + parts: { |
| 968 | + "word/document.xml": |
| 969 | + '<w:document xmlns:w="urn:w"><w:body><w:tbl>' + |
| 970 | + "<w:tr><w:tc><w:p><w:r><w:t>A</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>B</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>C</w:t></w:r></w:p></w:tc></w:tr>" + |
| 971 | + '<w:tr><w:tc><w:p><w:r><w:t>Tail</w:t></w:r></w:p></w:tc><w:tc><w:tcPr><w:gridSpan w:val="2"/></w:tcPr><w:p><w:r><w:t>End</w:t></w:r></w:p></w:tc></w:tr>' + |
| 972 | + '<w:tr><w:tc><w:tcPr><w:gridSpan w:val="2"/></w:tcPr><w:p><w:r><w:t>Merged</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>Total</w:t></w:r></w:p></w:tc></w:tr>' + |
| 973 | + '<w:tr><w:tc><w:tcPr><w:gridSpan w:val="0"/></w:tcPr><w:p><w:r><w:t>Zero</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>Next</w:t></w:r></w:p></w:tc></w:tr>' + |
| 974 | + '<w:tr><w:tc><w:tcPr><w:gridSpan w:val="513"/></w:tcPr><w:p><w:r><w:t>Wide</w:t></w:r></w:p></w:tc></w:tr>' + |
| 975 | + "</w:tbl></w:body></w:document>", |
| 976 | + }, |
| 977 | + expected: [ |
| 978 | + "A\tB\tC\nTail\tEnd\nMerged\t\tTotal\nZero\tNext", |
| 979 | + "[Extracted text truncated at document extraction limits.]", |
| 980 | + ], |
| 981 | + absent: ["Wide"], |
| 982 | + }, |
964 | 983 | { |
965 | 984 | ext: "docx", |
966 | 985 | bounded: true, |
|