- Timestamp:
- 12/10/2023 01:17:29 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r57116 r57179 330 330 331 331 /** 332 * Byte offset in input document where current token starts. 333 * 334 * Example: 335 * 336 * <div id="test">... 337 * 01234 338 * - token starts at 0 339 * 340 * @since 6.5.0 341 * 342 * @var int|null 343 */ 344 private $token_starts_at; 345 346 /** 347 * Byte length of current token. 348 * 349 * Example: 350 * 351 * <div id="test">... 352 * 012345678901234 353 * - token length is 14 - 0 = 14 354 * 355 * a <!-- comment --> is a token. 356 * 0123456789 123456789 123456789 357 * - token length is 17 - 2 = 15 358 * 359 * @since 6.5.0 360 * 361 * @var int|null 362 */ 363 private $token_length; 364 365 /** 332 366 * Byte offset in input document where current tag name starts. 333 367 * … … 339 373 * 340 374 * @since 6.2.0 375 * 341 376 * @var int|null 342 377 */ … … 353 388 * 354 389 * @since 6.2.0 390 * 355 391 * @var int|null 356 392 */ 357 393 private $tag_name_length; 358 359 /**360 * Byte offset in input document where current tag token ends.361 *362 * Example:363 *364 * <div id="test">...365 * 0 1 |366 * 01234567890123456367 * --- tag name ends at 14368 *369 * @since 6.2.0370 * @var int|null371 */372 private $tag_ends_at;373 394 374 395 /** … … 389 410 * // ^ parsing will continue from this point. 390 411 * $this->attributes = array( 391 * 'id' => new WP_HTML_Attribute_ Match( 'id', null, 6, 17)412 * 'id' => new WP_HTML_Attribute_Token( 'id', 9, 6, 5, 11, false ) 392 413 * ); 393 414 * … … 395 416 * // `class` attribute we will continue and add to this array. 396 417 * $this->attributes = array( 397 * 'id' => new WP_HTML_Attribute_ Match( 'id', null, 6, 17),398 * 'class' => new WP_HTML_Attribute_ Match( 'class', 'outline', 18, 32)418 * 'id' => new WP_HTML_Attribute_Token( 'id', 9, 6, 5, 11, false ), 419 * 'class' => new WP_HTML_Attribute_Token( 'class', 23, 7, 17, 13, false ) 399 420 * ); 400 421 * … … 485 506 * // Replace an attribute stored with a new value, indices 486 507 * // sourced from the lazily-parsed HTML recognizer. 487 * $start = $attributes['src']->start;488 * $ end = $attributes['src']->end;489 * $modifications[] = new WP_HTML_Text_Replacement( $start, $ end, $new_value );508 * $start = $attributes['src']->start; 509 * $length = $attributes['src']->length; 510 * $modifications[] = new WP_HTML_Text_Replacement( $start, $length, $new_value ); 490 511 * 491 512 * // Correspondingly, something like this will appear in this array. … … 567 588 return false; 568 589 } 569 $this->t ag_ends_at = $tag_ends_at;590 $this->token_length = $tag_ends_at - $this->token_starts_at; 570 591 $this->bytes_already_parsed = $tag_ends_at; 571 592 … … 809 830 } 810 831 811 $this->bookmarks[ $name ] = new WP_HTML_Span( 812 $this->tag_name_starts_at - ( $this->is_closing_tag ? 2 : 1 ), 813 $this->tag_ends_at 814 ); 832 $this->bookmarks[ $name ] = new WP_HTML_Span( $this->token_starts_at, $this->token_length ); 815 833 816 834 return true; … … 876 894 $at = strpos( $this->html, '</', $at ); 877 895 878 // If there is no possible tag closer then fail.896 // Fail if there is no possible tag closer. 879 897 if ( false === $at || ( $at + $tag_length ) >= $doc_length ) { 880 898 $this->bytes_already_parsed = $doc_length; … … 1094 1112 } 1095 1113 1114 $this->token_starts_at = $at; 1115 1096 1116 if ( '/' === $this->html[ $at + 1 ] ) { 1097 1117 $this->is_closing_tag = true; … … 1382 1402 $value_length, 1383 1403 $attribute_start, 1384 $attribute_end ,1404 $attribute_end - $attribute_start, 1385 1405 ! $has_value 1386 1406 ); … … 1397 1417 * normative case of parsing tags with no duplicate attributes. 1398 1418 */ 1399 $duplicate_span = new WP_HTML_Span( $attribute_start, $attribute_end );1419 $duplicate_span = new WP_HTML_Span( $attribute_start, $attribute_end - $attribute_start ); 1400 1420 if ( null === $this->duplicate_attributes ) { 1401 1421 $this->duplicate_attributes = array( $comparable_name => array( $duplicate_span ) ); … … 1425 1445 private function after_tag() { 1426 1446 $this->get_updated_html(); 1447 $this->token_starts_at = null; 1448 $this->token_length = null; 1427 1449 $this->tag_name_starts_at = null; 1428 1450 $this->tag_name_length = null; 1429 $this->tag_ends_at = null;1430 1451 $this->is_closing_tag = null; 1431 1452 $this->attributes = array(); … … 1607 1628 $output_buffer = ''; 1608 1629 foreach ( $this->lexical_updates as $diff ) { 1609 $shift = strlen( $diff->text ) - ( $diff->end - $diff->start );1630 $shift = strlen( $diff->text ) - $diff->length; 1610 1631 1611 1632 // Adjust the cursor position by however much an update affects it. … … 1621 1642 $output_buffer .= substr( $this->html, $bytes_already_copied, $diff->start - $bytes_already_copied ); 1622 1643 $output_buffer .= $diff->text; 1623 $bytes_already_copied = $diff-> end;1644 $bytes_already_copied = $diff->start + $diff->length; 1624 1645 } 1625 1646 … … 1631 1652 */ 1632 1653 foreach ( $this->bookmarks as $bookmark_name => $bookmark ) { 1654 $bookmark_end = $bookmark->start + $bookmark->length; 1655 1633 1656 /* 1634 1657 * Each lexical update which appears before the bookmark's endpoints … … 1641 1664 1642 1665 foreach ( $this->lexical_updates as $diff ) { 1643 if ( $bookmark->start < $diff->start && $bookmark->end < $diff->start ) { 1666 $diff_end = $diff->start + $diff->length; 1667 1668 if ( $bookmark->start < $diff->start && $bookmark_end < $diff->start ) { 1644 1669 break; 1645 1670 } 1646 1671 1647 if ( $bookmark->start >= $diff->start && $bookmark ->end < $diff->end ) {1672 if ( $bookmark->start >= $diff->start && $bookmark_end < $diff_end ) { 1648 1673 $this->release_bookmark( $bookmark_name ); 1649 1674 continue 2; 1650 1675 } 1651 1676 1652 $delta = strlen( $diff->text ) - ( $diff->end - $diff->start );1677 $delta = strlen( $diff->text ) - $diff->length; 1653 1678 1654 1679 if ( $bookmark->start >= $diff->start ) { … … 1656 1681 } 1657 1682 1658 if ( $bookmark ->end >= $diff->end ) {1683 if ( $bookmark_end >= $diff_end ) { 1659 1684 $tail_delta += $delta; 1660 1685 } 1661 1686 } 1662 1687 1663 $bookmark->start += $head_delta;1664 $bookmark-> end += $tail_delta;1688 $bookmark->start += $head_delta; 1689 $bookmark->length += $tail_delta - $head_delta; 1665 1690 } 1666 1691 … … 1744 1769 * start at the same location and contain the same text. 1745 1770 */ 1746 return $a-> end - $b->end;1771 return $a->length - $b->length; 1747 1772 } 1748 1773 … … 1972 1997 } 1973 1998 1974 return '/' === $this->html[ $this->tag_ends_at - 1 ]; 1999 /* 2000 * The self-closing flag is the solidus at the _end_ of the tag, not the beginning. 2001 * 2002 * Example: 2003 * 2004 * <figure /> 2005 * ^ this appears one character before the end of the closing ">". 2006 */ 2007 return '/' === $this->html[ $this->token_starts_at + $this->token_length - 1 ]; 1975 2008 } 1976 2009 … … 2102 2135 $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement( 2103 2136 $existing_attribute->start, 2104 $existing_attribute-> end,2137 $existing_attribute->length, 2105 2138 $updated_attribute 2106 2139 ); … … 2120 2153 $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement( 2121 2154 $this->tag_name_starts_at + $this->tag_name_length, 2122 $this->tag_name_starts_at + $this->tag_name_length,2155 0, 2123 2156 ' ' . $updated_attribute 2124 2157 ); … … 2195 2228 $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement( 2196 2229 $this->attributes[ $name ]->start, 2197 $this->attributes[ $name ]-> end,2230 $this->attributes[ $name ]->length, 2198 2231 '' 2199 2232 ); … … 2204 2237 $this->lexical_updates[] = new WP_HTML_Text_Replacement( 2205 2238 $attribute_token->start, 2206 $attribute_token-> end,2239 $attribute_token->length, 2207 2240 '' 2208 2241 ); … … 2290 2323 * be necessary for reparsing the current tag after updating the HTML. 2291 2324 */ 2292 $before_current_tag = $this->t ag_name_starts_at - 1;2325 $before_current_tag = $this->token_starts_at; 2293 2326 2294 2327 /* … … 2326 2359 2327 2360 $tag_ends_at = strpos( $this->html, '>', $this->bytes_already_parsed ); 2328 $this->t ag_ends_at = $tag_ends_at;2361 $this->token_length = $tag_ends_at - $this->token_starts_at; 2329 2362 $this->bytes_already_parsed = $tag_ends_at; 2330 2363
Note: See TracChangeset
for help on using the changeset viewer.