Skip to content

fix(pm-adapter): render bibliography/index/TOA inside documentPartObject (SD-3066)#3566

Open
tupizz wants to merge 1 commit into
tadeu/sd-3066-field-code-importfrom
tadeu/sd-3066-render-fields
Open

fix(pm-adapter): render bibliography/index/TOA inside documentPartObject (SD-3066)#3566
tupizz wants to merge 1 commit into
tadeu/sd-3066-field-code-importfrom
tadeu/sd-3066-render-fields

Conversation

@tupizz
Copy link
Copy Markdown
Contributor

@tupizz tupizz commented May 29, 2026

Note

📚 Stacked PRs — review bottom-up

Order PR Scope
1️⃣ #3538 Single-paragraph BIBLIOGRAPHY/INDEX/TOA crash (SD-3005)
2️⃣ #3565 super-editor — field-code import fidelity + DRY
3️⃣ #3566 pm-adapter — render fields inside documentPartObject 👈 this PR

Review order: #3538#3565#3566. Each PR's base auto-retargets to main as the one below it merges.


Summary

Word wraps a generated bibliography (and other block fields) in a docPartObject SDT, sometimes via a nested content control. The pm-adapter handler only converted paragraph and tableOfContents children to flow blocks, so the field's entry paragraphs were silently dropped — the heading rendered, the entries didn't.

Stacked on #3565 (which fixes the import side so these fields parse correctly). Base retargets to main as the stack merges.

Linear: SD-3066

Fix

  • documentPartObject now renders bibliography/index/tableOfAuthorities children via the shared handleParagraphContainerNode, and structuredContentBlock children via their handler.
  • structuredContentBlock recurses block-field children (transparent wrapper).

Section-counting invariant (the real hazard)

findParagraphsWithSectPr recurses bibliography but not structuredContentBlock. So:

  • direct bibliography → handler advances currentParagraphIndex per entry (matches analysis);
  • scb-wrapped → renders without advancing (matches analysis not recursing scb).

The prior code both dropped entries and under-counted, which could drift section breaks. Both paths are validated against the invariant.

Also extracts the shared handleParagraphContainerNode (previously three byte-identical copies in the bibliography/index/toa handlers).

Test plan

  • Regression tests for both nesting shapes + the counter behavior
  • pnpm --filter @superdoc/pm-adapter exec vitest run src/sdt src/sections src/internal.test.ts — 302 pass
  • Layout corpus (474 docs): 439 unchanged; the 35 changed are a verticalAlign schema-evolution + 7 image/table/section docs that contain zero docPartObj/bibliography — provably untouched by this change. No regressions attributable to the fix.
  • Browser-verified: bibliography+document.docx now renders the entries (matches Word)

…ect (SD-3066)

Word wraps a generated bibliography (and other block fields) in a docPartObject
SDT, sometimes via a nested content control. The handler only converted
paragraph and tableOfContents children to flow blocks, so the field's entry
paragraphs were silently dropped — the heading rendered but the entries did
not.

- documentPartObject now renders bibliography/index/tableOfAuthorities children
  via the shared paragraph-container handler, and structuredContentBlock
  children via their handler.
- structuredContentBlock recurses block-field children (transparent wrapper),
  rendering their paragraphs.

Section-counting invariant: findParagraphsWithSectPr recurses bibliography
(so the handler advances currentParagraphIndex per entry) but not
structuredContentBlock (so the scb path renders without advancing). Both paths
were validated against the invariant; the prior code dropped entries AND
under-counted, which could drift section breaks.

Also extracts the shared handleParagraphContainerNode used by the bibliography,
index and tableOfAuthorities handlers (previously three byte-identical copies).

Regression tests cover both nesting shapes and the counter behavior. pm-adapter
suite passes (302); layout corpus comparison shows no regressions attributable
to this change.

Linear: SD-3066
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 29, 2026

SD-3066

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread packages/layout-engine/pm-adapter/src/sdt/document-part-object.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant