Changeset 44389 for trunk/src/wp-includes/class-wp-block-parser.php
- Timestamp:
- 01/04/2019 07:37:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block-parser.php
r44360 r44389 1 1 <?php 2 /** 3 * Block Serialization Parser 4 * 5 * @package WordPress 6 */ 2 7 3 8 /** … … 63 68 public $innerContent; 64 69 70 /** 71 * Constructor. 72 * 73 * Will populate object properties from the provided arguments. 74 * 75 * @since 3.8.0 76 * 77 * @param string $name Name of block. 78 * @param array $attrs Optional set of attributes from block comment delimiters. 79 * @param array $innerBlocks List of inner blocks (of this same class). 80 * @param string $innerHTML Resultant HTML from inside block comment delimiters after removing inner blocks. 81 * @param array $innerContent List of string fragments and null markers where inner blocks were found. 82 */ 65 83 function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) { 66 84 $this->blockName = $name; … … 122 140 public $leading_html_start; 123 141 142 /** 143 * Constructor 144 * 145 * Will populate object properties from the provided arguments. 146 * 147 * @since 3.8.0 148 * 149 * @param WP_Block_Parser_Block $block Full or partial block. 150 * @param int $token_start Byte offset into document for start of parse token. 151 * @param int $token_length Byte length of entire parse token string. 152 * @param int $prev_offset Byte offset into document for after parse token ends. 153 * @param int $leading_html_start Byte offset into document where leading HTML before token starts. 154 */ 124 155 function __construct( $block, $token_start, $token_length, $prev_offset = null, $leading_html_start = null ) { 125 156 $this->block = $block; … … 191 222 * @since 3.8.0 192 223 * 193 * @param string $document 224 * @param string $document Input document being parsed. 194 225 * @return WP_Block_Parser_Block[] 195 226 */ … … 202 233 203 234 do { 204 // twiddle our thumbs 235 // twiddle our thumbs. 205 236 } while ( $this->proceed() ); 206 237 … … 227 258 $stack_depth = count( $this->stack ); 228 259 229 // we may have some HTML soup before the next block 260 // we may have some HTML soup before the next block. 230 261 $leading_html_start = $start_offset > $this->offset ? $this->offset : null; 231 262 232 263 switch ( $token_type ) { 233 264 case 'no-more-tokens': 234 // if not in a block then flush output 265 // if not in a block then flush output. 235 266 if ( 0 === $stack_depth ) { 236 267 $this->add_freeform(); … … 247 278 */ 248 279 249 // for the easy case we'll assume an implicit closer 280 // for the easy case we'll assume an implicit closer. 250 281 if ( 1 === $stack_depth ) { 251 282 $this->add_block_from_stack(); … … 284 315 } 285 316 286 // otherwise we found an inner block 317 // otherwise we found an inner block. 287 318 $this->add_inner_block( 288 319 new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), … … 294 325 295 326 case 'block-opener': 296 // track all newly-opened blocks on the stack 327 // track all newly-opened blocks on the stack. 297 328 array_push( 298 329 $this->stack, … … 324 355 } 325 356 326 // if we're not nesting then this is easy - close the block 357 // if we're not nesting then this is easy - close the block. 327 358 if ( 1 === $stack_depth ) { 328 359 $this->add_block_from_stack( $start_offset ); … … 351 382 352 383 default: 353 // This is an error 384 // This is an error. 354 385 $this->add_freeform(); 355 386 return false; … … 387 418 ); 388 419 389 // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE 420 // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE. 390 421 if ( false === $has_match ) { 391 422 return array( 'no-more-tokens', null, null, null, null ); 392 423 } 393 424 394 // we have no more tokens 425 // we have no more tokens. 395 426 if ( 0 === $has_match ) { 396 427 return array( 'no-more-tokens', null, null, null, null ); … … 420 451 */ 421 452 if ( $is_closer && ( $is_void || $has_attrs ) ) { 422 // we can ignore them since they don't hurt anything 453 // we can ignore them since they don't hurt anything. 423 454 } 424 455 … … 440 471 * @since 3.9.0 441 472 * 442 * @param string $innerHTML HTML content of block 443 * @return WP_Block_Parser_Block freeform block object 473 * @param string $innerHTML HTML content of block. 474 * @return WP_Block_Parser_Block freeform block object. 444 475 */ 445 476 function freeform( $innerHTML ) { … … 449 480 /** 450 481 * Pushes a length of text from the input document 451 * to the output list as a freeform block 482 * to the output list as a freeform block. 452 483 * 453 484 * @internal 454 485 * @since 3.8.0 455 * @param null $length how many bytes of document text to output 486 * @param null $length how many bytes of document text to output. 456 487 */ 457 488 function add_freeform( $length = null ) { … … 467 498 /** 468 499 * Given a block structure from memory pushes 469 * a new block to the output list 500 * a new block to the output list. 470 501 * 471 502 * @internal 472 503 * @since 3.8.0 473 * @param WP_Block_Parser_Block $block the block to add to the output474 * @param int $token_start byte offset into the document where the first token for the block starts475 * @param int $token_length byte length of entire block from start of opening token to end of closing token476 * @param int|null $last_offset last byte offset into document if continuing form earlier output504 * @param WP_Block_Parser_Block $block The block to add to the output. 505 * @param int $token_start Byte offset into the document where the first token for the block starts. 506 * @param int $token_length Byte length of entire block from start of opening token to end of closing token. 507 * @param int|null $last_offset Last byte offset into document if continuing form earlier output. 477 508 */ 478 509 function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { … … 491 522 492 523 /** 493 * Pushes the top block from the parsing stack to the output list 524 * Pushes the top block from the parsing stack to the output list. 494 525 * 495 526 * @internal 496 527 * @since 3.8.0 497 * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML 528 * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML. 498 529 */ 499 530 function add_block_from_stack( $end_offset = null ) {
Note: See TracChangeset
for help on using the changeset viewer.