From c03af9af552c9a3826abd9e4348b4a7a28ffd5e3 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Tue, 28 Jul 2026 07:07:59 -0400 Subject: [PATCH] Preserve class-owned column max width --- php-transformer/src/HtmlToBlocks/BlockFactory.php | 2 +- php-transformer/tests/contract/run.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/php-transformer/src/HtmlToBlocks/BlockFactory.php b/php-transformer/src/HtmlToBlocks/BlockFactory.php index ae1ed02b..d585f383 100644 --- a/php-transformer/src/HtmlToBlocks/BlockFactory.php +++ b/php-transformer/src/HtmlToBlocks/BlockFactory.php @@ -66,7 +66,7 @@ private function normalizeAttrsForBlock(string $name, array $attrs): array // These core save functions do not reproduce dimensions.maxWidth. Inline // max-width is retained by the generated geometry carrier stylesheet. - if ( in_array($name, array( 'core/group', 'core/columns', 'core/list-item', 'core/paragraph', 'core/separator' ), true) ) { + if ( in_array($name, array( 'core/group', 'core/column', 'core/columns', 'core/list-item', 'core/paragraph', 'core/separator' ), true) ) { unset($attrs['style']['dimensions']['maxWidth']); if ( empty($attrs['style']['dimensions']) ) { unset($attrs['style']['dimensions']); diff --git a/php-transformer/tests/contract/run.php b/php-transformer/tests/contract/run.php index b55fa9a8..edbddb39 100644 --- a/php-transformer/tests/contract/run.php +++ b/php-transformer/tests/contract/run.php @@ -744,6 +744,19 @@ public function match(DOMElement $element, PatternContext $context): ?array $assert(array('top' => '0', 'bottom' => '0') === ($boundedSeparatorAttrs['style']['spacing']['margin'] ?? null) && ! isset($boundedSeparatorAttrs['style']['dimensions']), 'separator keeps only spacing supported by its canonical core block attributes'); $assert(! str_contains($boundedSeparatorMarkup, 'margin-left:auto') && ! str_contains($boundedSeparatorMarkup, 'max-width:var(--max)') && str_contains($boundedSeparatorCss, 'margin-left:auto !important') && str_contains($boundedSeparatorCss, 'margin-right:auto !important') && str_contains($boundedSeparatorCss, 'max-width:var(--max) !important'), 'separator moves unsupported horizontal and width geometry to its generated carrier stylesheet'); +$boundedColumn = ( new HtmlTransformer() )->transform( + '

Article

Body

', + array('static_css' => ':root{--measure:42rem}.bounded-column{max-width:var(--measure);padding:1rem}') +)->toArray(); +$boundedColumnBlock = $boundedColumn['blocks'][0]['innerBlocks'][0] ?? array(); +$boundedColumnAttrs = $boundedColumnBlock['attrs'] ?? array(); +$boundedColumnMarkup = (string) ($boundedColumn['serialized_blocks'] ?? ''); +$boundedColumnCss = implode("\n", array_map(static fn (array $asset): string => (string) ($asset['content'] ?? ''), $boundedColumn['assets'] ?? array())); +$assert('core/column' === ($boundedColumnBlock['blockName'] ?? '') && 'bounded-column' === ($boundedColumnAttrs['className'] ?? ''), 'bounded source child becomes a core/column and retains its class-owned geometry selector'); +$assert(! isset($boundedColumnAttrs['style']['dimensions']['maxWidth']) && ! str_contains($boundedColumnMarkup, 'max-width:var(--measure)'), 'column omits max-width unsupported by its canonical Gutenberg save wrapper'); +$assert(str_contains($boundedColumnCss, '.bounded-column{max-width:var(--measure);padding:1rem}'), 'generated stylesheet retains the exact class-owned column max-width geometry'); +$assert('pass' === ($boundedColumn['source_reports']['wp_block_validity']['status'] ?? ''), 'bounded column serialization passes canonical Gutenberg wrapper validity'); + $customStateFindings = ( new CanonicalSaveShapeValidator() )->findings(array(array( 'blockName' => 'core/group', 'attrs' => array(),