fix: apply Heading style from BASE_STYLE_MAP level in Word output#5174
Open
Shengshenlan wants to merge 1 commit into
Open
fix: apply Heading style from BASE_STYLE_MAP level in Word output#5174Shengshenlan wants to merge 1 commit into
Shengshenlan wants to merge 1 commit into
Conversation
BASE_STYLE_MAP already defines a 'level' field for title-type blocks (doc_title=0, content_title=1, paragraph_title=2), but _set_paragraph_style never read it - all paragraphs were written as Normal style, so the generated .docx had no heading hierarchy (empty navigation pane, no TOC). This wires up the level field: when present and a doc reference is available, the paragraph is assigned the corresponding Word Heading style (level 0 -> Title, level N -> Heading N). Verified on a 3-page real tender document: before patch all paragraphs were Normal; after patch doc_title -> Title, paragraph_title -> Heading 2. Resolves PaddlePaddle#4207
|
Thanks for your contribution! |
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.
Problem
BASE_STYLE_MAPinword_converter.pyalready defines alevelfield for title-type blocks:However,
_set_paragraph_style()never readslevel— it only appliessize,bold,align, andindent. As a result, all paragraphs in the generated.docxareNormalstyle, including detected titles. Word's navigation pane, outline view, and auto-generated TOC are all empty.The
levelfield is defined but never consumed — this looks like a half-finished feature.Fix
Wire up the
levelfield in_set_paragraph_style:docparameter (defaults toNone, so existing callers are unaffected)config["level"]is present anddocis available, assign the corresponding Word style:level == 0→Titlelevel == N→Heading N_write_blockto passdocBefore / After
Tested on a real 3-page tender document (中文招标文件):
Before (all Normal):
After (headings applied):
Word navigation pane now shows the heading tree, and auto-TOC works.
Backward compatibility
docparameter defaults toNone— if not passed, behavior is unchanged (same as before)Resolves #4207