Skip to content

Keep section breaks that sit on a {%p %} tag paragraph - #204

Merged
cvas22 merged 1 commit into
mainfrom
fix/111-keep-section-break
Nov 25, 2026
Merged

cvas22 merged 1 commit into
mainfrom
fix/111-keep-section-break

Conversation

@cvas22

@cvas22 cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

When the paragraph that ends a section also holds a {%p %} tag, the p regex in patch_xml removes the whole paragraph, w:sectPr included. 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 original w:pPr. It goes before opening tags and after closing ones (endif, endfor), so the break stays outside the block and an if can't drop it and a for can't repeat it. Paragraphs without a section break are replaced exactly as before.

The new test puts the break on if, endif, for and endfor paragraphs, 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

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
@github-actions github-actions Bot added code Changes to the docform package tests Changes to tests labels Nov 25, 2026
@cvas22
cvas22 merged commit 4e3284b into main Nov 25, 2026
11 checks passed
@cvas22
cvas22 deleted the fix/111-keep-section-break branch November 25, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Changes to the docform package tests Changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom margins change to default ones

1 participant