fix: emit mirrorMargins in sectPr for Word for Mac PDF export (#74)#75
Merged
Merged
Conversation
#74) Word for Mac's "Save as PDF" / "Print to PDF" pipelines flatten the mirror on verso pages when <w:mirrorMargins/> lives only in settings.xml (the spec-compliant CT_Settings location). Defensively duplicate the element inside sectPr so the export pipeline picks it up; LibreOffice and Word for Windows ignore unknown sectPr children, so existing behaviour is preserved. This unblocks KDP paperback workflows that rely on MirrorMargins + MarginGutter to satisfy the 22.225 mm inner-margin requirement.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #75 +/- ##
==========================================
+ Coverage 89.16% 89.17% +0.01%
==========================================
Files 28 28
Lines 1606 1608 +2
Branches 205 206 +1
==========================================
+ Hits 1432 1434 +2
Misses 128 128
Partials 46 46 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
<w:mirrorMargins/>insidesectPrso Word for Mac's "Save as PDF" / "Print to PDF" pipeline mirrors verso pages correctly. The element is still emitted insettings.xmlper OOXML spec; Word for Windows and LibreOffice ignore unknownsectPrchildren, so behaviour is unchanged for them.MirrorMargins+MarginGutterto satisfy the 22.225 mm inner-margin requirement (701–828 page band).Fixes #74.
Why this works
OOXML spec (ECMA-376 §17.15.1.43) places
mirrorMarginsunderCT_Settings, which the current implementation already does. Empirically, Word for Mac's PDF export pipeline only honours the flag when it also appears undersectPr. Word's reader is tolerant of unknownsectPrchildren (per the spec's Markup Compatibility rules), so duplicating is a low-risk additive change rather than an alternative-location move.Changes
csharp-version/src/MarkdownToDocx.Core/OpenXml/OpenXmlDocumentBuilder.cs: append<w:mirrorMargins/>tosectPrwhenMirrorMargins == true.csharp-version/tests/MarkdownToDocx.Tests/Integration/MarkdownToDocxIntegrationTests.cs: regression tests verifying both presence (when enabled) and absence (when disabled) insectPrandsettings.xml.Test plan
dotnet test(320/320 passing locally)Build_WithMirrorMargins_ShouldEmitMirrorMarginsInBothSettingsAndSectPrBuild_WithoutMirrorMargins_ShouldNotEmitMirrorMarginsAnywhere