Add default top margin to tables preceded by paragraphs#109
Merged
Conversation
) 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
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
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.5ptwhen 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 marginw:tblpPr) withtopFromTextandbottomFromTextattributes.001ptmargin to ensure consistent renderingTest coverage in
HtmlConverterTests.cs: Added two comprehensive test casesHC056_TablePrecededByParagraph_HasTopMargin: Verifies tables getmargin-top: 7.5ptwhen preceded by paragraphs with no spacingHC057_TableWithParagraphSpacing_NoExtraMargin: Verifies no extra margin is added when preceding paragraph has explicit after-spacingDocumentation: 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.5pttop 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