From 15c3f036fd090dbadcdd535f2c05965a4af249b8 Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Wed, 13 Sep 2023 13:02:17 +0000 Subject: [PATCH] HTML API: Update documentation and rename internal variable on HTML Processor This patch updates documentation and an internal variable name within the HTML Processor class so that they are more helpful and complete to a reader. There should be no functional or visual changes in this patch. Props dmsnell, mukesh27. Fixes #59267. Built from https://develop.svn.wordpress.org/trunk@56565 git-svn-id: http://core.svn.wordpress.org/trunk@56077 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../html-api/class-wp-html-processor.php | 104 +++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 77 insertions(+), 29 deletions(-) diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php index 64fd23924e..52735f29e6 100644 --- a/wp-includes/html-api/class-wp-html-processor.php +++ b/wp-includes/html-api/class-wp-html-processor.php @@ -27,6 +27,7 @@ * - Unwrapping a tag by removing its parent. * - Inserting and removing nodes. * - Reading and changing inner content. + * - Navigating up or around HTML structure. * * ## Usage * @@ -66,7 +67,7 @@ * `array( 'IMG' )` matches all IMG elements and `array( 'P', 'IMG' )` * matches all IMG elements directly inside a P element. To ensure that no * partial matches erroneously match it's possible to specify in a query - * the full breadcrumb match. + * the full breadcrumb match all the way down from the root HTML element. * * Example: * @@ -76,7 +77,7 @@ * * $html = '
A lovely day outside
'; * // ---- Matches here. - * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'IMG', 'FIGCAPTION', 'EM' ) ) ); + * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'FIGCAPTION', 'EM' ) ) ); * * $html = '
'; * // ----- Matches here, because IMG must be a direct child of the implicit BODY. @@ -100,7 +101,8 @@ * * - Links: A. * - The formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U. - * - Containers: DIV, FIGCAPTION, FIGURE. + * - Containers: DIV, FIGCAPTION, FIGURE, SPAN. + * - Form elements: BUTTON. * - Paragraph: P. * - Void elements: IMG. * @@ -116,7 +118,9 @@ * - Markup involving only those tags listed above. * - Fully-balanced and non-overlapping tags. * - HTML with unexpected tag closers. + * - Some unbalanced or overlapping tags. * - P tags after unclosed P tags. + * - BUTTON tags after unclosed BUTTON tags. * - A tags after unclosed A tags that don't involve any active formatting elements. * * @since 6.4.0 @@ -126,7 +130,10 @@ */ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** - * HTML processing requires more bookmarks than basic tag processing. + * The maximum number of bookmarks allowed to exist at any given time. + * + * HTML processing requires more bookmarks than basic tag processing, + * so this class constant from the Tag Processor is overwritten. * * @since 6.4.0 * @@ -137,6 +144,8 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * Static query for instructing the Tag Processor to visit every token. * + * @access private + * * @since 6.4.0 * * @var array @@ -158,8 +167,15 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * Used to create unique bookmark names. * + * This class sets a bookmark for every tag in the HTML document that it encounters. + * The bookmark name is auto-generated and increments, starting with `1`. These are + * internal bookmarks and are automatically released when the referring WP_HTML_Token + * goes out of scope and is garbage-collected. + * * @since 6.4.0 * + * @see WP_HTML_Processor::$release_internal_bookmark_on_destruct + * * @var int */ private $bookmark_counter = 0; @@ -186,7 +202,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @var closure */ - private $release_internal_bookmark = null; + private $release_internal_bookmark_on_destruct = null; /* * Public Interface Functions @@ -258,10 +274,14 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * Constructor. * + * Do not use this method. Use the static creator methods instead. + * * @access private * * @since 6.4.0 * + * @see WP_HTML_Processor::createFragment() + * * @param string $html HTML to process. * @param string|null $use_the_static_create_methods_instead This constructor should not be called manually. */ @@ -287,7 +307,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * a private method into WP_HTML_Token classes without * exposing it to any public API. */ - $this->release_internal_bookmark = function ( $name ) { + $this->release_internal_bookmark_on_destruct = function ( $name ) { parent::release_bookmark( $name ); }; } @@ -298,13 +318,15 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * Various situations lead to parsing failure but this class will * return `false` in all those cases. To determine why something * failed it's possible to request the last error. This can be - * helpful to know if it's possible to fix something or to give up. + * helpful to know to distinguish whether a given tag couldn't + * be found or if content in the document caused the processor + * to give up and abort processing. * * Example * - * $p = WP_HTML_Processor::createFragment( '