Skip to content

fix(docx): render Word Title and Subtitle styles as headings - #2752

Open
ducduong97hn wants to merge 1 commit into
microsoft:mainfrom
ducduong97hn:fix/docx-title-subtitle-headings
Open

ducduong97hn wants to merge 1 commit into
microsoft:mainfrom
ducduong97hn:fix/docx-title-subtitle-headings

Conversation

@ducduong97hn

@ducduong97hn ducduong97hn commented Oct 24, 2026 •

Copy link
Copy Markdown

Fixes #329

Summary

Mammoth's default style map has no rules for Word's built-in Title and Subtitle paragraph styles, so DocxConverter emitted them as plain paragraphs and the document title lost its heading. For example, the existing test.docx fixture converted to:

AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation

Qingyun Wu , Gagan Bansal , ...

# Abstract

This adds two default style-map rules, Title → h1 and Subtitle → h2 (the mapping suggested as a workaround in the issue thread), so the same document now starts with:

# AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation

Details

  • The rules match the style name, not the style ID. Localized Word versions write their own style IDs: test.docx stores Title as a3 and Subtitle as a5, but the names are still Title and Subtitle.
  • The rules come after the caller's style_map and the document's embedded style map, so either one can still override them, e.g. style_map="p[style-name='Subtitle'] => p:fresh".
  • Title-styled paragraphs inside table cells still render as plain cell text, the same as Heading 1 does today.

Tests

  • The test.docx vector now expects # AutoGen: .... This fixture is a real Word document whose title uses a localized style ID, and the vector runs through the module and CLI entry points. It fails on main.
  • test_docx.py: new tests for Title/Subtitle → #/## (using the fixture's localized IDs) and for a caller style_map overriding the default.
  • markitdown-ocr: updated four DOCX snapshots whose fixtures start with a Title-styled paragraph (# Report, # Complex Document, ...).

Local runs (pytest, Python 3.10 on Windows): packages/markitdown 1174 passed, 3 skipped; packages/markitdown-ocr 108 passed. Black 26.10.1 reports no changes.

Mammoth's default style map has no rules for Word's built-in Title and
Subtitle paragraph styles, so a document's title came through as a plain
paragraph. Map Title to h1 and Subtitle to h2 by style name, because
localized Word versions write their own style IDs (test.docx stores Title
as "a3"). Caller and embedded style maps still take precedence.

Fixes microsoft#329
@ducduong97hn

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@ducduong97hn
ducduong97hn force-pushed the fix/docx-title-subtitle-headings branch from 3d444e1 to 48cd0eb Compare October 24, 2026 23:47
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.

Titles and subtitles not recognized on docx documents

2 participants