Repository navigation
Keep section breaks that sit on a {%p %} tag paragraph - #204
Merged
Merged
Conversation
A paragraph that ends a section holds the section's page size, margins
and orientation in w:pPr/w:sectPr. When that paragraph carries a {%p %}
tag it was removed along with its section break, so the section merged
into the next one and lost its layout. Keep an empty paragraph with the
same properties, before opening tags and after closing ones so an if or
for never drops or repeats it.
Fixes #111
This was referenced Nov 25, 2026
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.
When the paragraph that ends a section also holds a
{%p %}tag, thepregex inpatch_xmlremoves the whole paragraph,w:sectPrincluded. The section then merges into the next one and takes on its margins, page size and orientation. That matches the report in #111: custom margins reset depending on where the content and tags are.For
{%p %}paragraphs with a section break, the tag is now emitted next to an empty paragraph that keeps the originalw:pPr. It goes before opening tags and after closing ones (endif,endfor), so the break stays outside the block and anifcan't drop it and aforcan't repeat it. Paragraphs without a section break are replaced exactly as before.The new test puts the break on
if,endif,forandendforparagraphs, with the block shown and hidden, and checks there are still two sections with the first one's margin. All six cases fail on main. The trade-off is one empty paragraph where the section break was, which is what Word needs to hold the break anyway.Fixes #111