Skip to content

fix(docx): preserve Heading 7-9 styles by clamping to h6 (#2530) - #2630

Open
İlker Oğulcan SAYIN (iosayin) wants to merge 1 commit into
microsoft:mainfrom
iosayin:fix/2530-docx-heading-7-9
Open

İlker Oğulcan SAYIN (iosayin) wants to merge 1 commit into
microsoft:mainfrom
iosayin:fix/2530-docx-heading-7-9

Conversation

@iosayin

Copy link
Copy Markdown

Closes #2530

Summary

Word defines Heading styles 1 through 9, but Mammoth's default style map only maps Heading 1 through Heading 6. Paragraphs styled with Heading 7, Heading 8, or Heading 9 were previously dropped into plain <p> paragraphs, losing their document structure entirely.

Since Markdown only supports heading levels up to 6 (######), this PR maps Heading 7, 8, and 9 to h6:fresh (equivalent to ######), preserving the heading semantics and document hierarchy.

Changes

  • Added _HEADING_STYLE_MAP in _docx_converter.py mapping Heading7-Heading9 and Heading 7-Heading 9 to h6:fresh.
  • Added unit tests in tests/test_docx.py asserting that Heading 7, 8, and 9 are preserved as ######.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX: Heading 7-9 styles lose heading structure entirely (render as plain paragraphs)

1 participant