Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/server/src/provider/documentTextWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ const PARTIAL_DROPPED = new Set([
"row",
"tr",
"table-row",
"footnote",
"endnote",
]);

function xml(
Expand Down Expand Up @@ -1881,13 +1883,16 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
const styles = has(stylesPath) ? read(stylesPath, "definitions") : undefined;
const styleRunHidden = styles && wordStyleVisibility(styles);
const doc = readText(main, styleRunHidden);
let notesCut = false;
// Footnotes and endnotes live in their own parts; put each inline where it is referenced.
for (const kind of ["footnote", "endnote"]) {
const noteTarget = relationTarget(`${kind}s`);
const notePath = noteTarget && NodePath.posix.resolve(dir, noteTarget).slice(1);
if (!notePath || !has(notePath)) continue;
const bodies = new Map<string, string>();
for (const note of all(read(notePath, styleRunHidden), kind)) {
const notes = readText(notePath, styleRunHidden);
notesCut ||= notes.truncated === true;
for (const note of all(notes, kind)) {
const body = Array.from(wordNoteParagraphs(note), (paragraph) =>
[...text(paragraph)].filter((part) => typeof part === "string").join(""),
)
Expand Down Expand Up @@ -1929,6 +1934,7 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
}
yield* paragraphs(doc);
endIfCut(doc);
if (notesCut) throw new Truncation("XML node limit");
} else if ([".odt", ".ods", ".odp"].includes(extension)) {
const odfFamily = (): OdfStyleFamily => ({ common: new Map(), automatic: new Map() });
const odfTextStyles: OdfTextStyles | undefined =
Expand Down
44 changes: 44 additions & 0 deletions apps/server/src/provider/userInputAttachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,50 @@ describe("question answer paths", () => {
exact:
"The north region[Note: Inspect the seals.\nDo not reopen.] is ready. The south region[Note: Check power.] is ready.",
},
{
ext: "docx",
bounded: true,
parts: {
"word/document.xml":
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>' +
"<w:p><w:r><w:t>Findings at a glance.</w:t></w:r></w:p>" +
'<w:p><w:r><w:t>See the survey results.</w:t></w:r><w:r><w:footnoteReference w:id="1"/></w:r></w:p>' +
"</w:body></w:document>",
"word/_rels/document.xml.rels":
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>' +
"</Relationships>",
"word/footnotes.xml":
'<w:footnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:footnote w:id="1">' +
(
"<w:p>" +
'<w:r><w:rPr><w:b/></w:rPr><w:t>Sample</w:t></w:r><w:r><w:t xml:space="preserve"> recorded.</w:t></w:r>'.repeat(
5,
) +
"</w:p>"
).repeat(6_500) +
"</w:footnote></w:footnotes>",
},
expected: [
"Findings at a glance.\nSee the survey results.",
"[Extracted text truncated at document extraction limits.]",
],
},
{
ext: "docx",
bounded: true,
parts: {
"word/document.xml":
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>Survey closed.</w:t></w:r><w:r><w:endnoteReference w:id="1"/></w:r></w:p><w:p><w:r><w:t>Results follow.</w:t></w:r><w:r><w:endnoteReference w:id="2"/></w:r></w:p></w:body></w:document>',
"word/_rels/document.xml.rels":
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/></Relationships>',
"word/endnotes.xml": `<w:endnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:endnote w:id="1"><w:p><w:r><w:t>Held in May.</w:t></w:r></w:p>${"<w:p/>".repeat(199_995)}</w:endnote><w:endnote w:id="2"><w:p><w:r><w:t>Sample.</w:t></w:r></w:p></w:endnote></w:endnotes>`,
},
expected: [
"Survey closed.[Note: Held in May.]\nResults follow.\n",
"[Extracted text truncated",
],
},
{
ext: "odt",
parts: {
Expand Down
Loading