Skip to content

fix(doc2md): clamp Word Heading 7-9 to Markdown H6 (#18411) - #18418

Open
salimkt wants to merge 1 commit into
PaddlePaddle:mainfrom
salimkt:fix/doc2md-clamp-heading-level
Open

salimkt wants to merge 1 commit into
PaddlePaddle:mainfrom
salimkt:fix/doc2md-clamp-heading-level

Conversation

@salimkt

@salimkt salimkt commented Oct 26, 2026

Copy link
Copy Markdown

What

Word ships built-in Heading 1–Heading 9 styles, and _detect_heading_level() returned the style number as-is. CommonMark ATX headings allow at most six #, so Heading 7/8/9 came out as literal ####### … text and lost their heading status.

Change

_detect_heading_level() now returns min(level, 6), matching its docstring ("1-6 = heading level"). Deep headings degrade to H6.

Tests

tests/unit/test_doc2md_docx_headings.py builds a .docx with python-docx that uses Heading 1–9, and checks:

  • _detect_heading_level() returns 1–6, 6, 6, 6
  • DocxConverter().convert_file() emits at most six # for every heading.

The 7/8/9 cases and the end-to-end test fail on main, and all pass with the fix. They skip if python-docx is not installed.

Fixes #18411

🤖 Generated with Claude Code

Word has built-in Heading 1-9 styles, but CommonMark ATX headings stop at
six '#' markers, so Heading 7-9 were emitted as literal '####### ...'
text. Clamp the detected level to 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

doc2md: Word Heading 7/8/9 styles emit 7-9 '#' markers — invalid CommonMark (rendered as literal text, heading silently lost)

2 participants