Skip to content

bug: built-in Word heading styles not rendered when missing from styles.xml #2805

@gpardhivvarma

Description

@gpardhivvarma

Problem

Documents created with python-docx's doc.add_heading() render headings as unstyled body text in SuperDoc. The headings lose their font size, weight, and spacing.

Root Cause

doc.add_heading() creates paragraphs referencing Word's built-in heading styles (<w:pStyle w:val="Heading1"/>) without adding explicit <w:style> definitions in styles.xml. This is valid OOXML — Word has ~260 built-in styles that implicitly exist.

SuperDoc's style-engine (style-engine/src/ooxml/index.ts:283-284) returns {} when a styleId is not found in translatedLinkedStyles.styles, with no fallback to Word's built-in defaults. The existing test at index.test.ts:58-62 documents this: 'MissingStyle' silently returns empty.

The latentStyles element is parsed during import (super-converter/v3/handlers/w/latentStyles/) but is never used to provide fallback definitions.

Reproduction

from docx import Document

doc = Document()
doc.add_heading('Title', level=1)     # Uses built-in Heading 1 style
doc.add_heading('Subtitle', level=2)  # Uses built-in Heading 2 style
doc.add_paragraph('Body text')
doc.save('test.docx')

Open test.docx in SuperDoc — all three lines render identically as body text.

Expected Behavior

  • Heading 1: 26pt, bold, 12pt spacing before
  • Heading 2: 20pt, bold, 8pt spacing before
  • Body text: 11pt, normal weight

Per ECMA-376 §17.7.4.9, applications must provide built-in style defaults for standard style IDs when not explicitly defined in the document.

Suggested Fix

Add fallback logic in resolveStyleChain() at style-engine/src/ooxml/index.ts:283-284 to return Word's built-in heading properties when styleDef is undefined but styleId matches a known built-in pattern (Heading1Heading9).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions