Repository navigation
fix(docx): render Word Title and Subtitle styles as headings - #2752
Open
ducduong97hn wants to merge 1 commit into
Open
ducduong97hn wants to merge 1 commit into
ducduong97hn wants to merge 1 commit into
Conversation
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
Author
|
@microsoft-github-policy-service agree |
ducduong97hn
force-pushed
the
fix/docx-title-subtitle-headings
branch
from
October 24, 2026 23:47
3d444e1 to
48cd0eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #329
Summary
Mammoth's default style map has no rules for Word's built-in Title and Subtitle paragraph styles, so
DocxConverteremitted them as plain paragraphs and the document title lost its heading. For example, the existingtest.docxfixture converted to:AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation Qingyun Wu , Gagan Bansal , ... # AbstractThis adds two default style-map rules, Title →
h1and 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 ConversationDetails
test.docxstores Title asa3and Subtitle asa5, but the names are stillTitleandSubtitle.style_mapand the document's embedded style map, so either one can still override them, e.g.style_map="p[style-name='Subtitle'] => p:fresh".Heading 1does today.Tests
test.docxvector 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 onmain.test_docx.py: new tests for Title/Subtitle →#/##(using the fixture's localized IDs) and for a callerstyle_mapoverriding 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/markitdown1174 passed, 3 skipped;packages/markitdown-ocr108 passed. Black 26.10.1 reports no changes.