Skip to content

Add default top margin to tables preceded by paragraphs#109

Merged
JSv4 merged 1 commit intomainfrom
claude/investigate-issue-108-qNrfp
Mar 21, 2026
Merged

Add default top margin to tables preceded by paragraphs#109
JSv4 merged 1 commit intomainfrom
claude/investigate-issue-108-qNrfp

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Mar 20, 2026

Summary

This PR fixes an issue where tables preceded by paragraphs with no after-spacing were missing visual separation in the HTML output. Tables now receive a default margin-top: 7.5pt when appropriate, matching Word's implicit spacing behavior.

Key Changes

  • Table spacing logic in WmlToHtmlConverter.cs: Added logic to detect when a table is preceded by a paragraph without after-spacing and apply a default top margin

    • Handles floating table positioning properties (w:tblpPr) with topFromText and bottomFromText attributes
    • Checks preceding sibling elements to determine if default margin is needed
    • Skips default margin if the preceding paragraph already has explicit after-spacing
    • Applies fallback .001pt margin to ensure consistent rendering
  • Test coverage in HtmlConverterTests.cs: Added two comprehensive test cases

    • HC056_TablePrecededByParagraph_HasTopMargin: Verifies tables get margin-top: 7.5pt when preceded by paragraphs with no spacing
    • HC057_TableWithParagraphSpacing_NoExtraMargin: Verifies no extra margin is added when preceding paragraph has explicit after-spacing
  • Documentation: Updated CHANGELOG.md with details about the fix and its scope

Implementation Details

The solution examines the preceding sibling element when rendering a table. If it's a paragraph without after-spacing (or zero spacing), a default 7.5pt top margin is applied. This replicates Word's implicit spacing behavior and ensures proper visual separation in the HTML output. The logic respects explicit spacing attributes and floating table positioning properties, avoiding double-spacing scenarios.

https://claude.ai/code/session_01GqdXRFCZ8jnvmB88hpYnPh

)

Tables now get proper margin-top CSS when the preceding element lacks
after-spacing. Also handles floating table spacing from w:tblpPr
(topFromText/bottomFromText). When the preceding paragraph already
provides after-spacing, no extra margin is added.

https://claude.ai/code/session_01GqdXRFCZ8jnvmB88hpYnPh
@JSv4 JSv4 linked an issue Mar 20, 2026 that may be closed by this pull request
@JSv4 JSv4 merged commit 034e3ff into main Mar 21, 2026
10 checks passed
@JSv4 JSv4 deleted the claude/investigate-issue-108-qNrfp branch March 21, 2026 00:03
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.

Table containers missing top margin/padding when preceded by paragraphs

2 participants