markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

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

Open ManoharPaturi opened this issue 2 months ago • 0 comments

Description

Word defines Heading styles 1 through 9, but the DOCX converter (via mammoth's default style map) only maps Heading 1-6. Paragraphs styled Heading 7, 8, or 9 come through as plain <p> text, so their heading structure is silently dropped from the markdown.

Reproduction

import io
from docx import Document
from markitdown import MarkItDown, StreamInfo

doc = Document()
for level in range(1, 10):
    doc.add_heading(f"H{level}", level=level)
buf = io.BytesIO(); doc.save(buf); buf.seek(0)
print(MarkItDown().convert_stream(buf, stream_info=StreamInfo(extension=".docx")).markdown)
# H1..H6 render as #..###### but H7, H8, H9 render as plain paragraphs

Deep heading levels are common in legal and technical-spec documents.

Expected behavior

Markdown has no level past 6, so 7-9 clamp to ###### rather than losing the heading entirely.

Environment

markitdown main (945314a), python-docx + mammoth current

ManoharPaturi avatar Sep 18 '26 12:09 ManoharPaturi