Skip to content

SD-2508 - fix: toc not being displayed inside w:sdt#2850

Open
chittolinag wants to merge 3 commits intomainfrom
gabriel/sd-2508-bug-docpartobj-sdt-handler-drops-tables
Open

SD-2508 - fix: toc not being displayed inside w:sdt#2850
chittolinag wants to merge 3 commits intomainfrom
gabriel/sd-2508-bug-docpartobj-sdt-handler-drops-tables

Conversation

@chittolinag
Copy link
Copy Markdown
Contributor

@chittolinag chittolinag commented Apr 16, 2026

Issue

Documents with a TOC inside a w:sdt whose docPartGallery is not exactly "Table of Contents" (e.g. "Custom Table of Contents") have the TOC dropped on render.

The field preprocessor converts TOC field codes (w:fldChar begin/end) into a single sd:tableOfContents element regardless of the gallery type. This means the PM documentPartObject node for any custom TOC gallery ends up with a tableOfContents child.

handleDocumentPartObjectNode dispatches on docPartGallery === 'Table of Contents' for the processTocChildren path. For any other gallery string it falls to an else-if loop that only handled paragraph children — tableOfContents children were silently dropped.

Proposed solution

Add a tableOfContents branch to the else-if loop in document-part-object.ts that forwards to the existing processTocChildren helper. No changes to the import handler or preprocessing pipeline.

Side notes

This PR fixes the issue where the TOC is completely dropped and doesn't show up in the document. However, there are still rendering issues with the TOC. This other PR is open and fixes the rendering issue.

@linear
Copy link
Copy Markdown

linear bot commented Apr 16, 2026

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chittolinag chittolinag marked this pull request as ready for review April 16, 2026 18:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad510e09aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +82 to +83
child.content,
{ docPartGallery: docPartGallery ?? '', docPartObjectId, tocInstruction, sdtMetadata: docPartSdtMetadata },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve nested TOC instruction when forwarding child nodes

The new non-"Table of Contents" branch calls processTocChildren with child.content instead of the tableOfContents node itself, which drops the nested node context where processTocChildren reads getNodeInstruction(child) (toc.ts). In documents where a custom gallery stores the TOC field code on the nested tableOfContents node (the case this patch targets), tocInstruction now stays undefined and paragraph TOC metadata is incomplete, so downstream TOC behavior can differ from the standard gallery path.

Useful? React with 👍 / 👎.

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.

3 participants