mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-30 15:31:04 +01:00
cbc1c955d8
This patch introduces a new class: `WP_Token_Map`, designed for efficient lookup and translation of static mappings between string keys or tokens, and string replacements (for example, HTML character references). The Token Map imposes certain restrictions on the byte length of the lookup tokens and their replacements, but is a highly-optimized data structure for mappings with a very high number of tokens. Developed in https://github.com/WordPress/wordpress-develop/pull/5373 Discussed in https://core.trac.wordpress.org/ticket/60698 Fixes #60698. Props: dmsnell, gziolo, jonsurrell, jorbin. Built from https://develop.svn.wordpress.org/trunk@58188 git-svn-id: http://core.svn.wordpress.org/trunk@57651 1a063a9b-81f0-0310-95a4-ce76da25c4cd
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Adds the wp-block-list class to the rendered list block.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Adds the wp-block-list class to the rendered list block.
|
|
* Ensures that pre-existing list blocks use the class name on the front.
|
|
* For example, <ol> is transformed to <ol class="wp-block-list">.
|
|
*
|
|
* @since 6.6.0
|
|
*
|
|
* @see https://github.com/WordPress/gutenberg/issues/12420
|
|
*
|
|
* @param array $attributes Attributes of the block being rendered.
|
|
* @param string $content Content of the block being rendered.
|
|
*
|
|
* @return string The content of the block being rendered.
|
|
*/
|
|
function block_core_list_render( $attributes, $content ) {
|
|
if ( ! $content ) {
|
|
return $content;
|
|
}
|
|
|
|
$processor = new WP_HTML_Tag_Processor( $content );
|
|
|
|
$list_tags = array( 'OL', 'UL' );
|
|
while ( $processor->next_tag() ) {
|
|
if ( in_array( $processor->get_tag(), $list_tags, true ) ) {
|
|
$processor->add_class( 'wp-block-list' );
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $processor->get_updated_html();
|
|
}
|
|
|
|
/**
|
|
* Registers the `core/list` block on server.
|
|
*
|
|
* @since 6.6.0
|
|
*/
|
|
function register_block_core_list() {
|
|
register_block_type_from_metadata(
|
|
__DIR__ . '/list',
|
|
array(
|
|
'render_callback' => 'block_core_list_render',
|
|
)
|
|
);
|
|
}
|
|
|
|
add_action( 'init', 'register_block_core_list' );
|