Skip to content

fix: write one w:pBdr for a paragraph with both border and thematicBreak - #3935

Open
yschoi9733 wants to merge 1 commit into
dolanmiu:masterfrom
yschoi9733:fix/paragraph-border-thematic-break
Open

yschoi9733 wants to merge 1 commit into
dolanmiu:masterfrom
yschoi9733:fix/paragraph-border-thematic-break

Conversation

@yschoi9733

@yschoi9733 yschoi9733 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

A paragraph with both border and thematicBreak got a w:pBdr from each:

new Paragraph({
    border: { top: { style: BorderStyle.SINGLE, size: 12, color: "FF0000", space: 1 } },
    thematicBreak: true,
    children: [new TextRun("A red top border and a thematic break")],
});
<w:pPr>
  <w:pBdr><w:top w:val="single" w:color="FF0000" w:sz="12" w:space="1"/></w:pBdr>
  <w:pBdr><w:bottom w:val="single" w:color="auto" w:sz="6" w:space="1"/></w:pBdr>
</w:pPr>

CT_PPrBase has one pBdr (line 1099 of ooxml-schemas/ISO-IEC29500-4_2016/wml.xsd), so the Open XML SDK validator that the Demos workflow runs rejects the document for every Office version from 2010 to Microsoft 365: "The element has unexpected child element ... pBdr". A paragraph style with both options gets the same two elements in styles.xml, and so does htmlToContent for an <hr> in a <div> with a border, as the <hr>'s paragraph takes the box's border and thematicBreak.

Changes

  • ParagraphProperties writes one w:pBdr when both are set: border's sides, with the thematic break's line as the bottom border, in place of border.bottom if there is one.
  • For that, ThematicBreak extends Border and takes the paragraph's other borders as an optional argument, an Omit<IBordersOptions, "bottom">. Without it, it writes what it wrote before.
  • The JSDoc of border and ThematicBreak, and the Thematic Break section of docs/usage/paragraph.md, say how the two go together, and that of thematicBreak says the line is the paragraph's bottom border.

Why the line takes the place of border.bottom

That's how Word reads the two w:pBdr docx wrote: as one, with the sides of the first and the bottom of the second in place of the first one's. Word for Mac 16.115.1 draws a paragraph with red top, left and right borders and thematicBreak as a red box with a black bottom line. It draws one with a red top, a blue double border.bottom and thematicBreak with the red top and the black line, and no blue line. So this change keeps what Word shows: I exported five test documents to PDF from Word before and after the change, and each one's first page is the same, pixel for pixel. If you'd rather border.bottom won, it's a small change in ThematicBreak.

Layout

readParagraphFormat reads only the first w:pBdr, so the layout module left out the thematic break's line under a paragraph with a border. With a top border and thematicBreak on every other paragraph of the layout tests' 80-line probe, it put 48 lines on the first page. Word puts 45 there, as with top and bottom borders, and so does the layout module now: the test of top and bottom borders checks that case too.

For an <hr> in a <div> with a border, that means the layout module, like Word before and after this change, gives the <hr>'s paragraph a box of its own, as its bottom border isn't the same as those of the paragraphs beside it. Before, it kept the <hr>'s paragraph in one box with the paragraphs beside it, and left out the line. This PR doesn't change how htmlToContent converts an <hr>.

Checked

  • npm run test:ci (coverage stays at 100%), npm run lint, npm run prettier, npm run cspell and npm run check-api (no breaking changes against 9.16.0) pass.
  • With the Open XML SDK validator, for each Office version from 2010 to Microsoft 365, as the Demos workflow runs it: a paragraph with border without a bottom and thematicBreak, one with border.bottom and thematicBreak, a paragraph style with both and htmlToContent of an <hr> in a <div> with a border fail before the change and pass after it. A fifth document, with a paragraph with only thematicBreak and one with only border, passes before and after, with the same document.xml. The five demos that set a paragraph's thematicBreak or border pass after the change.
  • Word for Mac 16.115.1 renders the first pages of those five documents the same before and after the change, as above, and puts 45 lines on the first page of the layout probe before and after.
  • fix: leave ListParagraph off a bullet paragraph that has its own style #3926 and fix: stop writing a paragraph revision's run inside w:pPrChange #3928 change properties.ts too, in other lines, and each applies to this branch without conflicts.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Thematic-break lines can now appear alongside a paragraph’s top, left, right, and between borders. The line is drawn below the paragraph, and its default bottom border takes precedence over any specified bottom border.
  • Documentation
    • Clarified how thematic-break lines interact with paragraph borders.

A paragraph with both options got a w:pBdr from each, and CT_PPrBase has
one, so the Open XML SDK validator rejects the document. The same went for
paragraph styles, and for htmlToContent with an <hr> in a <div> with a
border.

The thematic break's line is now written in the w:pBdr of border, in place
of its bottom, as Word reads the two elements: ThematicBreak extends Border
and takes the paragraph's other borders. The layout module, which read only
the first w:pBdr, now gives the line its room, as Word does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Paragraphs with a thematic break now retain configured borders other than the bottom border. The thematic-break line replaces the configured bottom border. Formatter and layout tests cover paragraphs and paragraph styles with this combination.

Changes: Paragraph border behavior

Layer / File(s) Summary
Thematic-break border composition
src/file/paragraph/formatting/border.ts, src/file/paragraph/formatting/border.spec.ts
ThematicBreak extends Border and accepts paragraph borders other than bottom. It retains those borders and supplies its own single-line bottom border. The formatter test checks border order and the replacement bottom border.
Paragraph integration and verification
src/file/paragraph/properties.ts, src/file/paragraph/paragraph.spec.ts, src/file/styles/style/paragraph-style.spec.ts, src/layout/layout-document.spec.ts, docs/usage/paragraph.md
Paragraph properties pass configured borders to ThematicBreak. Tests cover formatted paragraph and style borders, plus layout expectations. The usage documentation describes the bottom-border replacement.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dolanmiu, devoidfury

Merge Risk: Minimal · up to f701d

The change makes paragraphs with both a border and a thematic break produce a single border element, which fixes the reported validation failure. The behavior is covered by tests and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a paragraph with both border and thematicBreak now writes one w:pBdr element. The raw summary and objectives confirm that ThematicBreak now takes the paragraph's other…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a paragraph with both border and thematicBreak now writes one w:pBdr element. The raw summary and objectives confirm that ThematicBreak now takes the paragraph's other borders and draws its line on the bottom of the shared element. The title is specific and short, and it has no file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbc01e9b-b4e2-4922-b7e3-4c5dd9f3df7a
Commits

Reviewing files that changed from the base of the PR and between f227ee1 and f701daf.

Files selected for processing: 7

  • docs/usage/paragraph.md
  • src/file/paragraph/formatting/border.spec.ts
  • src/file/paragraph/formatting/border.ts
  • src/file/paragraph/paragraph.spec.ts
  • src/file/paragraph/properties.ts
  • src/file/styles/style/paragraph-style.spec.ts
  • src/layout/layout-document.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f227ee1) to head (f701daf).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3935   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          576       576           
  Lines        27894     27892    -2     
  Branches     10204     10205    +1     
=========================================
- Hits         27894     27892    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant