Skip to content

fix: collapse adjacent quote-table spacers (#76)#77

Merged
forest6511 merged 1 commit into
mainfrom
feature/quote-table-spacer-collapse
May 5, 2026
Merged

fix: collapse adjacent quote-table spacers (#76)#77
forest6511 merged 1 commit into
mainfrom
feature/quote-table-spacer-collapse

Conversation

@forest6511
Copy link
Copy Markdown
Owner

Summary

  • Closes Quote (table-rendered): adjacent ::: blocks produce 2 spacer paragraphs and excessive vertical whitespace #76 — adjacent ::: note blocks rendered as single-cell tables (since bcecaf5) accumulated two spacer paragraphs between every pair, producing ~2 lines of visible whitespace.
  • AddCollapsingBeforeSpacer now collapses each block's before-spacer against an immediately preceding empty spacer paragraph, keeping max(prev.SpaceAfter, next.SpaceBefore) (CSS margin-collapse semantics).
  • Applied to both AddQuoteAsTable and AddTable, so the same regression in the rare adjacent-tables case is also fixed.
  • After-spacers are still emitted unconditionally — collapse happens at the next block's before-spacer, so the very last table/quote-table still gets its trailing gap.

Approach

Issue #76 listed three options. This PR is Option B (margin-collapse): more correct than the minimal Option A and a tiny amount more code (one helper + one predicate). When two adjacent quote-tables share the same SpaceBefore/SpaceAfter, the collapsed gap equals one spacer paragraph — matching the bcecaf5-prior paragraph rendering.

The detection (IsBodySpacerParagraph) treats any empty body-level paragraph with Before="0" and a non-empty After as collapsible. Heading after-spacers match this shape too, which is intentional — collapsing against a heading's after-spacer with max() never shrinks the gap, only avoids stacking.

Test plan

  • dotnet test (323 / 323 passing, 0 warnings introduced)
  • New: AddQuote_AdjacentTableQuotes_ShouldCollapseSpacersToSingleParagraph — three back-to-back quote-tables, asserts exactly one body element between every pair.
  • New: AddQuote_AdjacentTableQuotes_ShouldKeepLargerCollapsedSpacing — differing SpaceBefore/SpaceAfter collapse to max().
  • New: AddTable_AdjacentTables_ShouldCollapseSpacersToSingleParagraph — same rule for plain Markdown tables.
  • (recommended) Re-run a Vol.2 build of forest6511/rust-textbook-advanced and remove the Python post-processing workaround — no longer needed.

Adjacent ::: note blocks rendered as single-cell tables (bcecaf5) accumulated
two empty spacer paragraphs between every pair — the prior table's after-spacer
plus the next table's before-spacer — producing ~2 lines of unintended whitespace.

Make the before-spacer collapse against an immediately preceding spacer
paragraph using max(prev.SpaceAfter, next.SpaceBefore), mirroring CSS
margin-collapse semantics. Applied to both AddQuoteAsTable and AddTable so
consecutive plain tables benefit from the same fix.
@forest6511 forest6511 merged commit 19fcd3e into main May 5, 2026
1 check passed
@forest6511 forest6511 deleted the feature/quote-table-spacer-collapse branch May 5, 2026 17:24
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.90%. Comparing base (ee63cf7) to head (447d2ca).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...kdownToDocx.Core/OpenXml/OpenXmlDocumentBuilder.cs 64.70% 0 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #77      +/-   ##
==========================================
- Coverage   89.17%   88.90%   -0.27%     
==========================================
  Files          28       28              
  Lines        1608     1623      +15     
  Branches      206      215       +9     
==========================================
+ Hits         1434     1443       +9     
  Misses        128      128              
- Partials       46       52       +6     

☔ View full report in Codecov by Sentry.
📢 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.

forest6511 added a commit that referenced this pull request May 5, 2026
#78) (#79)

#76 / #77 only collapsed against empty spacer paragraphs, so the visible
blank-line regression remained at the heading-single-paragraph → quote-table
boundary (and at any text → quote-table boundary where the preceding
paragraph already supplied SpaceAfter).

Generalise AddCollapsingBeforeSpacer to fold the requested before-spacing
into the previous paragraph's SpacingBetweenLines.After whenever that After
is positive, regardless of whether the paragraph contains runs. This matches
CSS-like margin-collapse semantics and uniformly covers the table-table,
heading-table, and text-table boundaries. The IsBodySpacerParagraph helper
becomes unnecessary and is removed.
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.

Quote (table-rendered): adjacent ::: blocks produce 2 spacer paragraphs and excessive vertical whitespace

1 participant