Repository navigation
fix(docx-io): export line breaks the way Word writes them - #5161
Draft
vincent69001 wants to merge 1 commit into
Draft
vincent69001 wants to merge 1 commit into
vincent69001 wants to merge 1 commit into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: c22e236 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A `<br>` was written as `<w:br w:type="textWrapping"/>`, which Word for Mac displays as a labelled text wrapping break, and Word stretched the justified line that ends with it while browsers leave that line as is. Write the plain `<w:br/>` Word writes for Shift+Enter, and declare `w:doNotExpandShiftReturn` in the document settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vincent69001
force-pushed
the
fix/docx-io-line-breaks
branch
from
October 12, 2026 15:07
03e6d95 to
c22e236
Compare
This branch has not been deployed
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.
🐛 Fixes ➖ N/A
🧭 Task plan: docs/plans/2026-10-12-fix-docx-io-line-breaks.md
🟢 95% confidence in the verified package behavior
main,<p>first line<br>second line</p>exports<w:br w:type="textWrapping"/>andsettings.xmlhas now:compat: 2 of the 3 new tests failpnpm check✅ Outcome
htmlToDocxBlob, and thereforeexportToDocxandDocxExportPlugin, export a<br>the way Word itself writes and renders a Shift+Enter line break:main<br>indocument.xml<w:br w:type="textWrapping"/><w:br/><br><w:br w:type="page"/>Seen in Word for Mac on a downstream export (a contract with an address, a phone number and an email written line by line in a justified paragraph): each break showed a "[Saut de retour à la ligne]" label (French Word), and every line but the last was spread across the page. Writing the breaks without a type removed the labels; the compat setting removed the stretching.
w:typealready defaults totextWrappingin ECMA-376, so the label is how Word displays an explicitly typed break rather than a spec violation; the fix writes what Word writes for Shift+Enter.w:doNotExpandShiftReturnis a document-wide compatibility setting: a line break a reader later types with Shift+Enter in a justified paragraph is not stretched either, which is the same rule browsers apply. Word for Windows and Word Online were not checked by hand.🏗️ Design
The change is in the two places that write these parts.
buildLineBreakkeeps its export and now only writesw:typewhen a type is passed, so a caller can still ask forpageorcolumn; the<br>branch ofbuildRuncalls it without one. The settings template gains<w:compat><w:doNotExpandShiftReturn/></w:compat>betweenw:defaultTabStopandw:decimalSymbol, where CT_Settings puts it. No option was added: the converter renders HTML, and this setting is what makes Word render a<br>as the HTML does. Today a downstream app has to reopen the generated package and patch both XML parts to get this.🧪 Verified
mainwith the new tests: the untyped-break and compat tests fail, the page-break test passes.bun test ./packages/docx-io/src/lib/internal/html-to-docx.slow.ts: 36 pass.pnpm turbo build --filter=./packages/docx-io,pnpm turbo typecheck --filter=./packages/docx-io,pnpm turbo brl --filter=./packages/docx-io(no barrel drift),pnpm lint:fix,pnpm check: pass.AI-assisted (Claude Code), fully tested. Codex is not installed on the contributor's machine, so
codex review --base origin/mainwas not run; an independent Claude review pass was run on the diff instead: no correctness defect, and its accuracy findings (Word for Mac wording, document-wide scope, a test name) are applied.