Skip to content
Merged
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
18 changes: 16 additions & 2 deletions apps/server/src/provider/documentTextWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ function* paragraphs(node: XmlNode): Generator<TextPart, void> {
}
}
}
// A notes page also holds the slide image, slide number, date, header and footer placeholders.
const NOTES_PAGE_PLACEHOLDERS = new Set(["sldImg", "sldNum", "dt", "hdr", "ftr"]);
const isNotesPagePlaceholder = (node: XmlNode) =>
node.name === "sp" && NOTES_PAGE_PLACEHOLDERS.has(all(node, "ph").next().value?.attrs.type ?? "");
function withoutNotesPagePlaceholders(node: XmlNode): XmlNode {
return {
...node,
children: node.children
.filter((child) => typeof child === "string" || !isNotesPagePlaceholder(child))
.map((child) => (typeof child === "string" ? child : withoutNotesPagePlaceholders(child))),
};
}
function* inCell(parts: Iterable<TextPart>): Generator<TextPart, void> {
yield CELL_START;
yield* parts;
Expand Down Expand Up @@ -733,14 +745,16 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
!target
)
continue;
yield "Notes:\n";
yield* paragraphs(
const notesPage = withoutNotesPagePlaceholders(
read(
target.startsWith("/")
? target.slice(1)
: NodePath.posix.join(NodePath.posix.dirname(name), target),
),
);
if (!hasCellText(notesPage)) continue;
yield "Notes:\n";
yield* paragraphs(notesPage);
}
}
} else if (extension === ".epub") {
Expand Down
29 changes: 27 additions & 2 deletions apps/server/src/provider/userInputAttachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ describe("question answer paths", () => {
"ppt/slides/_rels/slide1.xml.rels":
'<Relationships><Relationship Type="http://purl.oclc.org/ooxml/officeDocument/relationships/notesSlide" Target="/ppt/notesSlides/notes3.xml"/></Relationships>',
"ppt/notesSlides/notes7.xml":
"<p:notes><a:p><a:r><a:t>evacuation code ORCHID-81</a:t></a:r></a:p></p:notes>",
'<p:notes><p:cSld><p:spTree><p:sp><p:nvSpPr><p:nvPr><p:ph type="sldImg"/></p:nvPr></p:nvSpPr></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:r><a:t>evacuation code ORCHID-81</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="hdr" sz="quarter"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:r><a:t>Harbor briefing</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="dt" idx="1"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:fld type="datetime1"><a:t>11/21/2026</a:t></a:fld></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="ftr" sz="quarter" idx="4"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:r><a:t>Crew only</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="sldNum" sz="quarter" idx="5"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:fld type="slidenum"><a:t>57</a:t></a:fld></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:notes>',
"ppt/notesSlides/notes3.xml":
"<p:notes><a:p><a:r><a:t>Board at gate 4</a:t></a:r></a:p></p:notes>",
"ppt/notesSlides/ignored.xml": "<p:notes><a:p>Unrelated notes</a:p></p:notes>",
Expand All @@ -1001,7 +1001,32 @@ describe("question answer paths", () => {
"Departure\nNotes:\nBoard at gate 4",
],
occurrences: { text: "## Slide ", count: 2 },
absent: ["Unrelated notes", "[Skipped document part", "[Extracted text truncated"],
absent: [
"Unrelated notes",
"Harbor briefing",
"11/21/2026",
"Crew only",
"57",
"[Skipped document part",
"[Extracted text truncated",
],
},
{
ext: "pptx",
bounded: true,
parts: {
"ppt/presentation.xml":
'<presentation><sldIdLst><sldId r:id="a"/></sldIdLst></presentation>',
"ppt/_rels/presentation.xml.rels":
'<Relationships><Relationship Id="a" Target="slides/a.xml"/></Relationships>',
"ppt/slides/a.xml": "<slide><p>Slide text</p></slide>",
"ppt/slides/_rels/a.xml.rels":
'<Relationships><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notesSlides/empty.xml"/></Relationships>',
"ppt/notesSlides/empty.xml":
'<p:notes><p:cSld><p:spTree><p:sp><p:nvSpPr><p:nvPr><p:ph type="sldImg"/></p:nvPr></p:nvSpPr></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:endParaRPr/></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:nvPr><p:ph type="sldNum" idx="5"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:fld type="slidenum"><a:t>57</a:t></a:fld></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:notes>',
},
expected: ["Slide text"],
absent: ["Notes:", "57"],
},
...[false, true].map((missing) => ({
ext: "pptx",
Expand Down
Loading