Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -917,29 +917,32 @@ 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;
}
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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ function serialize_blocks(array $blocks): string
$assert(\strpos($service_card_serialized, '<p class="service-number">01</p>') === \false, 'service-card-classed-span-not-rewritten-to-paragraph', $service_card_serialized);
$assert(\strpos($service_card_serialized, '<h3 class="wp-block-heading">Heels &amp; soles</h3>') !== \false, 'service-card-heading-remains-editable', $service_card_serialized);
$assert(\strpos($service_card_serialized, '<p>Heel lifts and sole patching.</p>') !== \false, 'service-card-copy-remains-editable', $service_card_serialized);
$tag_label_grid = <<<'HTML'
<div class="collection-grid">
<article class="collection"><span class="tag">window seats</span><h3>Deep built-in bench cushions</h3><p>Thicker cores and boxed corners.</p></article>
<article class="collection"><span class="tag">dining chairs</span><h3>Flattened chair pads</h3><p>Firm low-profile foam.</p></article>
</div>
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, '<span class="tag">window seats</span>') !== \false, 'card-tag-span-preserved', $tag_label_serialized);
$assert(\strpos($tag_label_serialized, '<p style="margin-top:0;margin-right:0;margin-bottom:0;margin-left:0"><span class="tag">window seats</span></p>') !== \false, 'card-tag-wrapper-resets-margin', $tag_label_serialized);
$extrachill_shell_grid = <<<'HTML'
<div class="full-width-breakout ec-edge-shell">
<div class="home-3x3-grid">
Expand Down
Loading