fix(style-engine): resolve built-in Word heading styles when missing from styles.xml#2806
fix(style-engine): resolve built-in Word heading styles when missing from styles.xml#2806gpardhivvarma wants to merge 2 commits intosuperdoc-dev:mainfrom
Conversation
…from styles.xml Add fallback to Word's built-in heading defaults (Heading1–Heading6) in resolveStyleChain() when a referenced style is not explicitly defined in the document's styles.xml. Also apply fallback in the basedOn chain walk so custom styles inheriting from built-in headings resolve correctly. Documents created with python-docx's add_heading() reference built-in styles without adding definitions — this is valid OOXML but previously rendered as unstyled body text. Closes superdoc-dev#2805
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99418295be
ℹ️ 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".
Addresses Codex review feedback — extend BUILTIN_STYLE_DEFAULTS to cover all nine heading levels. Heading7-9 use muted text color (595959) instead of the accent color used by Heading1-6, matching Word's visual hierarchy.
|
Addressed the Codex feedback — pushed a follow-up commit adding Heading7–Heading9. Note: |
Summary
Closes #2805
resolveStyleChain()when a referenced style is not defined in the document'sstyles.xmlbasedOnchain walk so custom styles inheriting from built-in headings resolve correctlyresolveRunPropertiesandresolveParagraphPropertiesProblem
Documents created with python-docx's
add_heading()reference Word's built-in heading styles (Heading1–Heading9) without adding explicit<w:style>definitions tostyles.xml. This is valid OOXML — Word has ~260 built-in styles that implicitly exist. SuperDoc'sresolveStyleChain()returned{}for these, causing headings to render as unstyled body text.Changes
style-engine/src/ooxml/builtin-styles.tsBUILTIN_STYLE_DEFAULTSmap with Heading1–6 properties matching Word defaults (font sizes, spacing, outline levels, theme fonts, colors)style-engine/src/ooxml/index.ts??fallback to built-in defaults in both initial lookup and basedOn chain walkstyle-engine/src/ooxml/index.test.tsHow it works
Document-defined styles always win (
??only activates when the left operand isundefined). Built-in headings setbasedOn: 'Normal', so the existing chain walk picks up the document's Normal style for font family and body defaults.Test plan
bun testin style-engine — 137/137 passingadd_heading()document