Support CSS border-spacing on tables#1321
Merged
Merged
Conversation
The parser only honored the legacy cellspacing attribute; the border-spacing property was ignored from any source, even though default.css declared it, and the writer never emitted cell spacing, so it was lost on every HTML round trip. - Parse border-spacing (one- and two-value forms) from the cascade, with browser precedence: border-collapse:collapse forces zero, CSS beats the cellspacing attribute, falling back to the 0.5pt margin importer default. Margins are now tracked per axis so asymmetric spacing lays out correctly. - Emit border-spacing on the table tag when the cells' margins differ from the default, so cellspacing/border-spacing survives writing. - Remove the dead border-spacing declaration from default.css: with the property now honored, the merged cascade would let it override every cellspacing attribute and the Apple-parity 0.5pt default. Co-Authored-By: Claude Fable 5 <[email protected]>
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
border-spacingwas declared in default.css but never consumed by the table parser — only the legacycellspacingattribute worked — and the HTML writer never emitted cell spacing, so any spacing was silently lost on an HTML → attributed string → HTML round trip (e.g.cellspacing="10"came back as the 1px default).BuilderState+Tables.swift):handleTableStartnow readsborder-spacingfrom the CSS cascade (inline styles and stylesheets), supporting the one-value and two-value (horizontal vertical) forms. Precedence follows browsers:border-collapse: collapseforces zero spacing, CSSborder-spacingbeats thecellspacingattribute, and the 0.5pt-margin importer default applies otherwise. Cell margins are tracked per axis, so asymmetric spacing lays out correctly (layout already reads margins per edge).HTMLWriter.swift): the<table>tag emitsborder-spacing(first cell's margins × 2) whenever it differs from the 1px default, collapsed to one value when both axes match. Collapsed tables skip it.border-spacing: 2pxdeclaration. Now that the property is honored, the merged cascade cannot distinguish UA-origin from author-origin styles, so keeping it would override everycellspacingattribute and change the plain-table default away from the Apple-importer-parity 0.5pt margin pinned byTextBlockAppKitParityTests.Test plan
border-spacing, CSS-over-attribute precedence, and collapse-ignores-spacing.cellspacing="10"is written asborder-spacing:10pxand reparses to 5pt margins;border-spacing: 8px 4pxsurvives asymmetrically; default tables emit noborder-spacing.🤖 Generated with Claude Code