Repository navigation
Conversation
Scan {{p var }} placeholder style and alignment before patch_xml and
apply them to plain Subdoc body paragraphs during render().
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
When a template uses
{{p var }},patch_xmlstrips the enclosing<w:p>(including
w:pStyle/ alignment) before Jinja runs. Body paragraphs in aSubdoc therefore ignore the style the author applied to the placeholder line.
Proposal
Before
patch_xmlremoves{{p var }}paragraphs, scan for style/alignment.At
render()time, apply those to plain body paragraphs of anySubdocin thecontext keyed by that variable name (Heading / List / Title / Subtitle left
unchanged). First occurrence wins.
Works for programmatic
new_subdoc()and for Subdocs created by other means(e.g. JSON CLI envelopes from a separate PR).
Implementation
docxtpl.p_style(scan_p_placeholder_styles,apply_p_placeholder_styles)DocxTemplate.render(), beforebuild_xml/patch_xmlscan_p_placeholder_stylesfromdocxtplHow to try
cd tests python subdoc_p_style.py