- Timestamp:
- 11/28/2024 02:25:51 PM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r59467 r59469 280 280 * impact the parse, such as with a SCRIPT tag and its `type` attribute. 281 281 * 282 * Example: 283 * 284 * // Usually, snippets of HTML ought to be processed in the default `<body>` context: 285 * $processor = WP_HTML_Processor::create_fragment( '<p>Hi</p>' ); 286 * 287 * // Some fragments should be processed in the correct context like this SVG: 288 * $processor = WP_HTML_Processor::create_fragment( '<rect width="10" height="10" />', '<svg>' ); 289 * 290 * // This fragment with TD tags should be processed in a TR context: 291 * $processor = WP_HTML_Processor::create_fragment( 292 * '<td>1<td>2<td>3', 293 * '<table><tbody><tr>' 294 * ); 295 * 296 * In order to create a fragment processor at the correct location, the 297 * provided fragment will be processed as part of a full HTML document. 298 * The processor will search for the last opener tag in the document and 299 * create a fragment processor at that location. The document will be 300 * forced into "no-quirks" mode by including the HTML5 doctype. 301 * 302 * For advanced usage and precise control over the context element, use 303 * `WP_HTML_Processor::create_full_processor()` and 304 * `WP_HTML_Processor::create_fragment_at_current_node()`. 305 * 306 * UTF-8 is the only allowed encoding. If working with a document that 307 * isn't UTF-8, first convert the document to UTF-8, then pass in the 308 * converted HTML. 282 * ## Current HTML Support 283 * 284 * - The only supported context is `<body>`, which is the default value. 285 * - The only supported document encoding is `UTF-8`, which is the default value. 309 286 * 310 287 * @since 6.4.0 311 288 * @since 6.6.0 Returns `static` instead of `self` so it can create subclass instances. 312 * @since 6.8.0 Can create fragments with any context element.313 289 * 314 290 * @param string $html Input HTML fragment to process. 315 * @param string $context Context element for the fragment . Defaults to`<body>`.291 * @param string $context Context element for the fragment, must be default of `<body>`. 316 292 * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. 317 293 * @return static|null The created processor if successful, otherwise null. 318 294 */ 319 295 public static function create_fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) { 296 if ( '<body>' !== $context || 'UTF-8' !== $encoding ) { 297 return null; 298 } 299 320 300 $context_processor = static::create_full_parser( "<!DOCTYPE html>{$context}", $encoding ); 321 301 if ( null === $context_processor ) { … … 476 456 * @return static|null The created processor if successful, otherwise null. 477 457 */ 478 p ublicfunction create_fragment_at_current_node( string $html ) {458 private function create_fragment_at_current_node( string $html ) { 479 459 if ( $this->get_token_type() !== '#tag' || $this->is_tag_closer() ) { 480 460 _doing_it_wrong(
Note: See TracChangeset
for help on using the changeset viewer.