diff --git a/packages/file-parse/src/docx.ts b/packages/file-parse/src/docx.ts index 9185beb..4557127 100644 --- a/packages/file-parse/src/docx.ts +++ b/packages/file-parse/src/docx.ts @@ -33,6 +33,16 @@ export async function docxToText(bytes: Uint8Array): Promise { } } } + // Footnotes/endnotes live outside the block tree but are part of the + // document's readable text (and what AI Q&A over attachments should index). + if (doc.footnotes.length > 0) { + lines.push('## Footnotes') + for (const note of doc.footnotes) lines.push(note.text) + } + if (doc.endnotes.length > 0) { + lines.push('## Endnotes') + for (const note of doc.endnotes) lines.push(note.text) + } return lines.join('\n') } diff --git a/packages/file-parse/tests/office-formats.test.ts b/packages/file-parse/tests/office-formats.test.ts index ef0af8b..1e6ad58 100644 --- a/packages/file-parse/tests/office-formats.test.ts +++ b/packages/file-parse/tests/office-formats.test.ts @@ -37,6 +37,35 @@ describe('parseFileToText: docx', () => { expect(result.text).toContain('Metric | Value') expect(result.text).toContain('Revenue | 100') }) + + it('includes footnote and endnote text', async () => { + const zip = await JSZip.loadAsync(await buildDocxFixture()) + const part = (tag: string, id: string, text: string) => + `${text}` + zip.file( + 'word/footnotes.xml', + '' + + '' + + part('footnote', '-1', '') + + part('footnote', '1', 'Footnote detail') + + '', + ) + zip.file( + 'word/endnotes.xml', + '' + + '' + + part('endnote', '1', 'Endnote detail') + + '', + ) + const path = writeFixture( + 'notes.docx', + await zip.generateAsync({ type: 'uint8array', compression: 'DEFLATE' }), + ) + const result = await parseFileToText(path) + expect(result.ok).toBe(true) + expect(result.text).toContain('Footnote detail') + expect(result.text).toContain('Endnote detail') + }) }) describe('parseFileToText: ppt', () => {