Skip to content

Collapse typography-only text wrappers to styled paragraphs (#630)#684

Merged
chubes4 merged 1 commit into
trunkfrom
fix/630-styled-text-wrapper-collapse
Jul 23, 2026
Merged

Collapse typography-only text wrappers to styled paragraphs (#630)#684
chubes4 merged 1 commit into
trunkfrom
fix/630-styled-text-wrapper-collapse

Conversation

@chubes4

@chubes4 chubes4 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

A styled <div>/<span> whose only content is inline text and whose CSS is typographic (font-size, letter-spacing, text-transform, color — no box-model geometry) was round-tripped as a core/group wrapping a default core/paragraph. That structure has two defects:

  1. Font scale is lost — the wrapper class (e.g. .label{font-size:0.68rem}) applies to the group <div>, but the inner default paragraph renders at the theme's base paragraph size instead of inheriting the wrapper's scale.
  2. Default block spacing is introduced — the inner paragraph gets a default block margin-top, adding vertical space the source never had.

On imported artist-site routes, an eyebrow like <div class="label">The Shop</div> rendered at the wrong size and injected a uniform ~21px top offset that shifted every following block down the page (measured: page-header inflated 458.6px → 479.7px; merch-intro/grid/footer all shifted +21px with no accumulation).

Fix

visualTextWrapperBlockFromElement() now emits a single styled core/paragraph carrying the wrapper class when the wrapper is a pure-text leaf (no child elements) with no box-model styling. Wrappers that own box-model geometry — padding, border, explicit sizing, or flex/grid layout (.tag, .tier-price, .use-case-result) — still round-trip as core/group so their block-level layout is preserved.

Box-model detection reads the raw matched declarations via structuralPresentationDeclarations() rather than the post-projection presentation set, so padding consumed into block-supports attributes is still seen.

Verification

Proven directly against the real fixture — fixtures/websites/3-artist-music/merch.html now compiles the eyebrow as:

<!-- wp:paragraph {"className":"label pl pl-d1","content":"The Shop"} --><p class="label pl pl-d1">The Shop</p><!-- /wp:paragraph -->

Full php-transformer suite green:

  • 248 parity fixtures — no regressions
  • 75 block-style-support conversion tests (box-model wrappers stay groups; typography-only .tier-name now collapses to a styled paragraph)
  • wordpress-site-plan + shared-shell-plan contracts, HTML-to-blocks contract

The block-style-support tests were updated to encode the corrected contract: box-model wrappers stay core/group; typography-only text wrappers collapse to styled paragraphs.

AI assistance disclosure

Drafted with Claude (Sonnet 4.5) via opencode, used to root-cause the offset from DOM snapshots and implement the box-model-aware collapse. Every line reviewed by Chris Huber.

Refs #630.

A styled `<div>`/`<span>` whose only content is inline text and whose CSS
is typographic (no box-model geometry) was round-tripped as a `core/group`
wrapping a default `core/paragraph`. That form does not inherit the wrapper's
typographic scale onto the inner paragraph and does not suppress default block
spacing, so an eyebrow like `<div class="label">The Shop</div>` rendered at the
wrong font size and introduced a ~21px top offset that shifted every following
block down the page (visible across imported artist-site routes).

visualTextWrapperBlockFromElement now emits a single styled `core/paragraph`
carrying the wrapper class when the wrapper is a pure-text leaf with no
box-model styling (padding/border/explicit sizing/flex-grid). Wrappers that own
box-model geometry (`.tag`, `.tier-price`, `.use-case-result`) still round-trip
as `core/group` so their block-level layout is preserved. Box-model detection
reads the raw matched declarations via structuralPresentationDeclarations so
padding consumed into block-supports attributes is still seen.

Updates block-style-support conversion tests: box-model wrappers stay groups;
the typography-only `.tier-name` label now collapses to a styled paragraph.

Full php-transformer suite green: 248 parity fixtures, 75 block-style-support
tests, wordpress-site-plan + shared-shell-plan contracts.

Refs #630.

AI assistance: drafted with Claude (Sonnet 4.5) via opencode; DOM-snapshot
root-cause and implementation reviewed by Chris Huber.
@chubes4
chubes4 merged commit 0a6b8df into trunk Jul 23, 2026
4 checks passed
@chubes4
chubes4 deleted the fix/630-styled-text-wrapper-collapse branch July 23, 2026 12:12
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