diff --git a/vendor_prefixed/chubes4/html-to-blocks-converter/includes/class-transform-registry.php b/vendor_prefixed/chubes4/html-to-blocks-converter/includes/class-transform-registry.php index c8ac1b3..83d0654 100644 --- a/vendor_prefixed/chubes4/html-to-blocks-converter/includes/class-transform-registry.php +++ b/vendor_prefixed/chubes4/html-to-blocks-converter/includes/class-transform-registry.php @@ -738,7 +738,7 @@ private static function get_button_transforms() }, 'transform' => function ($element) { return self::create_aria_hidden_inline_span_paragraph($element); }), array('blockName' => 'core/paragraph', 'priority' => 8, 'selector' => 'span', 'isMatch' => function ($element) { - return self::is_numeric_label_span($element); + return self::is_inline_span_label($element); }, 'transform' => function ($element) { return self::create_inline_span_label_paragraph($element); }), array('blockName' => 'core/group', 'priority' => 8, 'selector' => 'div,p', 'isMatch' => function ($element) { @@ -917,16 +917,16 @@ private static function create_static_visual_button_paragraph($element): array return HTML_To_Blocks_Block_Factory::create_block('core/paragraph', $attributes); } /** - * Checks whether a standalone span is a numeric visual label. + * Checks whether a standalone span is a visual label. * - * Number-only label spans are commonly used as service, step, or index badges. - * Keep the span markup inside a native paragraph so class-based presentation - * survives without falling back to core/html. + * Number-only and tag label spans are commonly used as service, step, index, + * and card badges. Keep the span markup inside a native paragraph so + * class-based presentation survives without falling back to core/html. * * @param HTML_To_Blocks_HTML_Element $element Element to inspect. * @return bool True when the span can safely become paragraph markup. */ - private static function is_numeric_label_span($element): bool + private static function is_inline_span_label($element): bool { if ('SPAN' !== $element->get_tag_name() || !$element->has_attribute('class')) { return \false; @@ -934,12 +934,15 @@ private static function is_numeric_label_span($element): bool if (\preg_match('/<\s*[a-z][^>]*>/i', $element->get_inner_html()) === 1) { return \false; } - return \preg_match('/^\d+$/', \trim($element->get_text_content())) === 1; + if (\preg_match('/^\d+$/', \trim($element->get_text_content())) === 1) { + return \true; + } + return self::class_matches($element, '/(?:^|\s)tag(?:\s|$)/i'); } /** - * Creates a paragraph preserving numeric label span markup. + * Creates a paragraph preserving inline label span markup. * - * @param HTML_To_Blocks_HTML_Element $element Numeric label span. + * @param HTML_To_Blocks_HTML_Element $element Inline label span. * @return array Block array. */ private static function create_inline_span_label_paragraph($element): array @@ -3352,6 +3355,9 @@ private static function get_paragraph_transforms() if (\in_array($element->get_tag_name(), array('P', 'ADDRESS', 'A'), \true)) { return \true; } + if (self::is_inline_span_label($element)) { + return \true; + } if (self::is_static_visual_label($element)) { return \true; } @@ -3360,6 +3366,9 @@ private static function get_paragraph_transforms() } return \in_array($element->get_tag_name(), array('DIV', 'SPAN'), \true) && array() === $element->get_child_elements() && \trim($element->get_text_content()) !== ''; }, 'transform' => function ($element) { + if (self::is_inline_span_label($element)) { + return self::create_inline_span_label_paragraph($element); + } $content = $element->get_tag_name() === 'A' ? self::get_paragraph_anchor_content($element) : $element->get_inner_html(); if (self::is_static_checkbox_label($element)) { $content = \trim(\preg_replace('/<\s*input\b[^>]*>/i', '', $content)); diff --git a/vendor_prefixed/chubes4/html-to-blocks-converter/tests/smoke-repeated-card-grid-transforms.php b/vendor_prefixed/chubes4/html-to-blocks-converter/tests/smoke-repeated-card-grid-transforms.php index a4feaeb..91341a7 100644 --- a/vendor_prefixed/chubes4/html-to-blocks-converter/tests/smoke-repeated-card-grid-transforms.php +++ b/vendor_prefixed/chubes4/html-to-blocks-converter/tests/smoke-repeated-card-grid-transforms.php @@ -227,6 +227,16 @@ function serialize_blocks(array $blocks): string $assert(\strpos($service_card_serialized, '

01

') === \false, 'service-card-classed-span-not-rewritten-to-paragraph', $service_card_serialized); $assert(\strpos($service_card_serialized, '

Heels & soles

') !== \false, 'service-card-heading-remains-editable', $service_card_serialized); $assert(\strpos($service_card_serialized, '

Heel lifts and sole patching.

') !== \false, 'service-card-copy-remains-editable', $service_card_serialized); +$tag_label_grid = <<<'HTML' +
+
window seats

Deep built-in bench cushions

Thicker cores and boxed corners.

+
dining chairs

Flattened chair pads

Firm low-profile foam.

+
+HTML; +$tag_label_blocks = html_to_blocks_raw_handler(['HTML' => $tag_label_grid]); +$tag_label_serialized = serialize_blocks($tag_label_blocks); +$assert(\strpos($tag_label_serialized, 'window seats') !== \false, 'card-tag-span-preserved', $tag_label_serialized); +$assert(\strpos($tag_label_serialized, '

window seats

') !== \false, 'card-tag-wrapper-resets-margin', $tag_label_serialized); $extrachill_shell_grid = <<<'HTML'