Repository navigation
fix(pptx): preserve slide page numbers for untitled slides - #1413
Conversation
Goldziher
left a comment
There was a problem hiding this comment.
Thanks — this is a real fix for a real defect, and test_internal_slide_markers_set_table_and_list_page_numbers genuinely fails without it and asserts exact values (page_number == 3, page == Some(3)) rather than truthiness. I want it in. Four things first.
First, a heads-up that isn't your fault
No CI has run on this PR at all. Not "green" — zero check runs on 1d51f0b0; gh pr checks reports "no checks reported". It's a cross-repository PR and our workflows never fired. So the 38 passed / 2,315 passed / clippy clean in your description is your local run, which I believe, but nothing has independently compiled this. I'll get CI running before merge; flagging it so neither of us mistakes silence for success.
1. The "\n\n" split is still the structural source of truth
extractors/pptx.rs:69 — content.split("\n\n") — is unchanged. What changed is which token advances the counter: # headings before, <!-- Slide number: N --> now. That is a genuine improvement, and I'm not asking you to rewrite the extractor. But it keeps us deriving document structure by re-parsing our own rendered markdown, which is what #1412 was really about, so:
A deck can spoof the marker. The only guard is (1..=slide_count).contains(&number). A text box containing the literal string <!-- Slide number: 5 --> — or a deck built from our own extracted output — is indistinguishable from a real boundary and silently re-stamps every table and list after it. Please make the marker unforgeable rather than merely well-behaved: emit it out-of-band, or carry the slide index alongside the string instead of inside it. DocumentStructureBuilder already exists on this path (extraction/pptx/mod.rs:182-186) but every call site hardcodes include_structure: false — that's the seam if you want it.
2. An untested behaviour change: PPTX loses its Slide node
Previously, an all-untitled deck left slide_num == 0 and fell into push_slide(1, None, Some(1)) at pptx.rs:154-156. A marker now always sets slide_num >= 1, so that branch is dead for any real deck and PPTX output will never emit an ElementKind::Slide again. That's visible downstream — rendering/comrak_bridge.rs:811 emits a ThematicBreak for it, rendering/json.rs:403-412 emits a JsonNode::Slide — so markdown loses a leading --- and JSON loses a node.
It's arguably an improvement (the old node claimed to be slide 1 of an 8-slide deck), but it's unmentioned and untested. Please either keep the branch reachable or delete it and add a test asserting the new output shape.
3. Finish the job while you're in there
push_heading (pptx.rs:89) and push_paragraph (pptx.rs:145) still pass page: None, even though slide_num is now correct and in scope right there. Paragraph elements from PPTX stay page-less for no reason. Two-line change, same defect.
4. Two smaller notes
add_slide_headeralready had a call site atextraction/pptx/mod.rs:602-603gated onconfig.include_slide_comment— which defaults tofalse(elements.rs:211) and is never set anywhere. You've added a second, unconditional emitter, so the same marker now has two paths with different semantics. Please reconcile them.PageBoundarybyte offsets shift.start_slidecapturesbyte_startbefore the new marker, so each boundary range now includes its own comment, and content always begins with"\n\n"where it previously began with slide text. The chunker recomputes frompagesso this is mostly harmless, butmetadata.pages.boundariesis API-visible and its values change. Worth a line in the PR description at minimum.
Testing
The regression test drives build_internal_document with a hand-written string, so the issue's own reproduction — a real PPTX with an untitled slide plus a table — isn't covered end to end. create_test_pptx_bytes only emits short text slides, which all become titles via the <100-char fallback (extraction/pptx/mod.rs:625-636), so this needs a new fixture builder. Please add one; that's the test that would have caught #1412 in the first place.
No binding impact — nothing here is public or reachable from the FFI surface, and PptxExtractor carries alef(skip). Nothing needs regenerating.
Separately: #1418 is the same defect in the legacy .ppt extractor and is being fixed structurally, not with markers. Worth keeping the two approaches from diverging.
|
Thanks for the detailed review. I pushed
I also replaced the hand-written-only regression with an end-to-end PPTX fixture containing an untitled long paragraph plus a table. Current local verification is 40 PPTX tests, the 2,317-test office library run with the missing corpus skipped, clippy with |
Goldziher
left a comment
There was a problem hiding this comment.
Approving. All four items from the previous review are addressed, and the approach changed rather than the symptom: the archive slide number now travels out-of-band in PptxInternalExtraction::slide_contents instead of being re-parsed out of rendered markdown, so item 1 is fixed structurally rather than guarded.
Since no CI has ever run on this PR (0 check runs, cross-repository), I verified locally on f1483b9 rather than taking the description on trust:
cargo test -p xberg --features office --lib pptx— 52 passed, 0 failed, including all three new tests.cargo check -p xberg --features office(non-test) — exit 0. This one mattered: the PR putsextract_pptx_from_bytesbehind#[cfg(test)], so a--libtest run cannot prove the non-test build still links. It does.cargo clippy -p xberg --features full --all-targets -- -D warnings— exit 0.
An office-only --all-targets clippy leg is red on make_ole_package/test_documents_dir dead code, but that is pre-existing from 94a2369a4c gating those tests on excel while leaving the helpers, in a file this PR does not touch. Not yours.
Two notes for the record, neither blocking:
- The notes-appending block in
extraction/pptx/mod.rs:225-233duplicatescontent_builder.rs:204-214(minus the trailing newline, which is harmless since blocks are trimmed). Two copies of the### Notes:/Notes:convention can now drift independently. !saw_titlecorrectly preserves the legacy sentinel, and the e2e test pins it. Worth knowing it is now keyed on any titled slide anywhere in the deck rather than on the counter, which is the same shape but not the same predicate.
Merging.
Related
Fixes #1412.
Description
PptxInternalExtractionvalue instead of embedding a forgeable marker in user-controlled Markdown.ElementKind::Slidesentinel while avoiding new slide nodes for titled decks.Tables and list items after untitled slides now retain their actual slide number. Marker-like text inside a deck remains ordinary content and cannot restamp later elements.
Validation
cargo test -p xberg --features office --lib 'pptx::tests::'— 40 passedXBERG_SKIP_TEST_DOCUMENTS=1 cargo test -p xberg --features office --lib— 2,317 passedcargo clippy -p xberg --features office --lib -- -D warningscargo fmt --all -- --checkgit diff --checkThe corpus skip is needed only because this shallow checkout does not initialize the
test_documentssubmodule.Checklist