@wordpress/block-serialization-default-parser
Advanced tools
+2
-0
@@ -0,1 +1,3 @@ | ||
| ## 2.0.2 (2018-12-12) | ||
| ## 2.0.1 (2018-11-30) | ||
@@ -2,0 +4,0 @@ |
+2
-2
| { | ||
| "name": "@wordpress/block-serialization-default-parser", | ||
| "version": "2.0.2", | ||
| "version": "2.0.3", | ||
| "description": "Block serialization specification parser for WordPress posts.", | ||
@@ -32,3 +32,3 @@ "author": "The WordPress Contributors", | ||
| }, | ||
| "gitHead": "e7e72e1a211f8426cb136c86d2948f497a03e1e4" | ||
| "gitHead": "f0223019510166b34593ba197568ca760d2983e7" | ||
| } |
+100
-62
| <?php | ||
| /** | ||
| * Block Serialization Parser | ||
| * | ||
| * @package WordPress | ||
| */ | ||
@@ -65,7 +70,20 @@ /** | ||
| /** | ||
| * Constructor. | ||
| * | ||
| * Will populate object properties from the provided arguments. | ||
| * | ||
| * @since 3.8.0 | ||
| * | ||
| * @param string $name Name of block. | ||
| * @param array $attrs Optional set of attributes from block comment delimiters. | ||
| * @param array $innerBlocks List of inner blocks (of this same class). | ||
| * @param string $innerHTML Resultant HTML from inside block comment delimiters after removing inner blocks. | ||
| * @param array $innerContent List of string fragments and null markers where inner blocks were found. | ||
| */ | ||
| function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) { | ||
| $this->blockName = $name; | ||
| $this->attrs = $attrs; | ||
| $this->innerBlocks = $innerBlocks; | ||
| $this->innerHTML = $innerHTML; | ||
| $this->blockName = $name; | ||
| $this->attrs = $attrs; | ||
| $this->innerBlocks = $innerBlocks; | ||
| $this->innerHTML = $innerHTML; | ||
| $this->innerContent = $innerContent; | ||
@@ -125,2 +143,15 @@ } | ||
| /** | ||
| * Constructor | ||
| * | ||
| * Will populate object properties from the provided arguments. | ||
| * | ||
| * @since 3.8.0 | ||
| * | ||
| * @param WP_Block_Parser_Block $block Full or partial block. | ||
| * @param int $token_start Byte offset into document for start of parse token. | ||
| * @param int $token_length Byte length of entire parse token string. | ||
| * @param int $prev_offset Byte offset into document for after parse token ends. | ||
| * @param int $leading_html_start Byte offset into document where leading HTML before token starts. | ||
| */ | ||
| function __construct( $block, $token_start, $token_length, $prev_offset = null, $leading_html_start = null ) { | ||
@@ -195,3 +226,3 @@ $this->block = $block; | ||
| * | ||
| * @param string $document | ||
| * @param string $document Input document being parsed. | ||
| * @return WP_Block_Parser_Block[] | ||
@@ -207,3 +238,3 @@ */ | ||
| do { | ||
| // twiddle our thumbs | ||
| // twiddle our thumbs. | ||
| } while ( $this->proceed() ); | ||
@@ -233,3 +264,3 @@ | ||
| // we may have some HTML soup before the next block | ||
| // we may have some HTML soup before the next block. | ||
| $leading_html_start = $start_offset > $this->offset ? $this->offset : null; | ||
@@ -239,3 +270,3 @@ | ||
| case 'no-more-tokens': | ||
| // if not in a block then flush output | ||
| // if not in a block then flush output. | ||
| if ( 0 === $stack_depth ) { | ||
@@ -255,3 +286,3 @@ $this->add_freeform(); | ||
| // for the easy case we'll assume an implicit closer | ||
| // for the easy case we'll assume an implicit closer. | ||
| if ( 1 === $stack_depth ) { | ||
@@ -279,15 +310,17 @@ $this->add_block_from_stack(); | ||
| if ( isset( $leading_html_start ) ) { | ||
| $this->output[] = (array) self::freeform( substr( | ||
| $this->document, | ||
| $leading_html_start, | ||
| $start_offset - $leading_html_start | ||
| ) ); | ||
| $this->output[] = (array) self::freeform( | ||
| substr( | ||
| $this->document, | ||
| $leading_html_start, | ||
| $start_offset - $leading_html_start | ||
| ) | ||
| ); | ||
| } | ||
| $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ); | ||
| $this->offset = $start_offset + $token_length; | ||
| $this->offset = $start_offset + $token_length; | ||
| return true; | ||
| } | ||
| // otherwise we found an inner block | ||
| // otherwise we found an inner block. | ||
| $this->add_inner_block( | ||
@@ -302,10 +335,13 @@ new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), | ||
| case 'block-opener': | ||
| // track all newly-opened blocks on the stack | ||
| array_push( $this->stack, new WP_Block_Parser_Frame( | ||
| new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), | ||
| $start_offset, | ||
| $token_length, | ||
| $start_offset + $token_length, | ||
| $leading_html_start | ||
| ) ); | ||
| // track all newly-opened blocks on the stack. | ||
| array_push( | ||
| $this->stack, | ||
| new WP_Block_Parser_Frame( | ||
| new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), | ||
| $start_offset, | ||
| $token_length, | ||
| $start_offset + $token_length, | ||
| $leading_html_start | ||
| ) | ||
| ); | ||
| $this->offset = $start_offset + $token_length; | ||
@@ -330,3 +366,3 @@ return true; | ||
| // if we're not nesting then this is easy - close the block | ||
| // if we're not nesting then this is easy - close the block. | ||
| if ( 1 === $stack_depth ) { | ||
@@ -342,7 +378,7 @@ $this->add_block_from_stack( $start_offset ); | ||
| */ | ||
| $stack_top = array_pop( $this->stack ); | ||
| $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset ); | ||
| $stack_top->block->innerHTML .= $html; | ||
| $stack_top = array_pop( $this->stack ); | ||
| $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset ); | ||
| $stack_top->block->innerHTML .= $html; | ||
| $stack_top->block->innerContent[] = $html; | ||
| $stack_top->prev_offset = $start_offset + $token_length; | ||
| $stack_top->prev_offset = $start_offset + $token_length; | ||
@@ -359,3 +395,3 @@ $this->add_inner_block( | ||
| default: | ||
| // This is an error | ||
| // This is an error. | ||
| $this->add_freeform(); | ||
@@ -396,3 +432,3 @@ return false; | ||
| // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE | ||
| // if we get here we probably have catastrophic backtracking or out-of-memory in the PCRE. | ||
| if ( false === $has_match ) { | ||
@@ -402,3 +438,3 @@ return array( 'no-more-tokens', null, null, null, null ); | ||
| // we have no more tokens | ||
| // we have no more tokens. | ||
| if ( 0 === $has_match ) { | ||
@@ -408,11 +444,11 @@ return array( 'no-more-tokens', null, null, null, null ); | ||
| list( $match, $started_at ) = $matches[ 0 ]; | ||
| list( $match, $started_at ) = $matches[0]; | ||
| $length = strlen( $match ); | ||
| $is_closer = isset( $matches[ 'closer' ] ) && -1 !== $matches[ 'closer' ][ 1 ]; | ||
| $is_void = isset( $matches[ 'void' ] ) && -1 !== $matches[ 'void' ][ 1 ]; | ||
| $namespace = $matches[ 'namespace' ]; | ||
| $namespace = ( isset( $namespace ) && -1 !== $namespace[ 1 ] ) ? $namespace[ 0 ] : 'core/'; | ||
| $name = $namespace . $matches[ 'name' ][ 0 ]; | ||
| $has_attrs = isset( $matches[ 'attrs' ] ) && -1 !== $matches[ 'attrs' ][ 1 ]; | ||
| $is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1]; | ||
| $is_void = isset( $matches['void'] ) && -1 !== $matches['void'][1]; | ||
| $namespace = $matches['namespace']; | ||
| $namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/'; | ||
| $name = $namespace . $matches['name'][0]; | ||
| $has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1]; | ||
@@ -424,3 +460,3 @@ /* | ||
| $attrs = $has_attrs | ||
| ? json_decode( $matches[ 'attrs' ][ 0 ], /* as-associative */ true ) | ||
| ? json_decode( $matches['attrs'][0], /* as-associative */ true ) | ||
| : $this->empty_attrs; | ||
@@ -433,3 +469,3 @@ | ||
| if ( $is_closer && ( $is_void || $has_attrs ) ) { | ||
| // we can ignore them since they don't hurt anything | ||
| // we can ignore them since they don't hurt anything. | ||
| } | ||
@@ -454,4 +490,4 @@ | ||
| * | ||
| * @param string $innerHTML HTML content of block | ||
| * @return WP_Block_Parser_Block freeform block object | ||
| * @param string $innerHTML HTML content of block. | ||
| * @return WP_Block_Parser_Block freeform block object. | ||
| */ | ||
@@ -464,7 +500,7 @@ function freeform( $innerHTML ) { | ||
| * Pushes a length of text from the input document | ||
| * to the output list as a freeform block | ||
| * to the output list as a freeform block. | ||
| * | ||
| * @internal | ||
| * @since 3.8.0 | ||
| * @param null $length how many bytes of document text to output | ||
| * @param null $length how many bytes of document text to output. | ||
| */ | ||
@@ -483,18 +519,18 @@ function add_freeform( $length = null ) { | ||
| * Given a block structure from memory pushes | ||
| * a new block to the output list | ||
| * a new block to the output list. | ||
| * | ||
| * @internal | ||
| * @since 3.8.0 | ||
| * @param WP_Block_Parser_Block $block the block to add to the output | ||
| * @param int $token_start byte offset into the document where the first token for the block starts | ||
| * @param int $token_length byte length of entire block from start of opening token to end of closing token | ||
| * @param int|null $last_offset last byte offset into document if continuing form earlier output | ||
| * @param WP_Block_Parser_Block $block The block to add to the output. | ||
| * @param int $token_start Byte offset into the document where the first token for the block starts. | ||
| * @param int $token_length Byte length of entire block from start of opening token to end of closing token. | ||
| * @param int|null $last_offset Last byte offset into document if continuing form earlier output. | ||
| */ | ||
| function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { | ||
| $parent = $this->stack[ count( $this->stack ) - 1 ]; | ||
| $parent = $this->stack[ count( $this->stack ) - 1 ]; | ||
| $parent->block->innerBlocks[] = (array) $block; | ||
| $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); | ||
| $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); | ||
| if ( ! empty( $html ) ) { | ||
| $parent->block->innerHTML .= $html; | ||
| $parent->block->innerHTML .= $html; | ||
| $parent->block->innerContent[] = $html; | ||
@@ -504,11 +540,11 @@ } | ||
| $parent->block->innerContent[] = null; | ||
| $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length; | ||
| $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length; | ||
| } | ||
| /** | ||
| * Pushes the top block from the parsing stack to the output list | ||
| * Pushes the top block from the parsing stack to the output list. | ||
| * | ||
| * @internal | ||
| * @since 3.8.0 | ||
| * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML | ||
| * @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML. | ||
| */ | ||
@@ -524,3 +560,3 @@ function add_block_from_stack( $end_offset = null ) { | ||
| if ( ! empty( $html ) ) { | ||
| $stack_top->block->innerHTML .= $html; | ||
| $stack_top->block->innerHTML .= $html; | ||
| $stack_top->block->innerContent[] = $html; | ||
@@ -530,7 +566,9 @@ } | ||
| if ( isset( $stack_top->leading_html_start ) ) { | ||
| $this->output[] = (array) self::freeform( substr( | ||
| $this->document, | ||
| $stack_top->leading_html_start, | ||
| $stack_top->token_start - $stack_top->leading_html_start | ||
| ) ); | ||
| $this->output[] = (array) self::freeform( | ||
| substr( | ||
| $this->document, | ||
| $stack_top->leading_html_start, | ||
| $stack_top->token_start - $stack_top->leading_html_start | ||
| ) | ||
| ); | ||
| } | ||
@@ -537,0 +575,0 @@ |
| <?php | ||
| /** | ||
| * PHP Test Helper | ||
| * | ||
| * Facilitates running PHP parser against same tests as the JS parser implementation. | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
| require_once __DIR__ . '/../parser.php'; | ||
| // Include the default parser. | ||
| require_once dirname( __FILE__ ) . '/../parser.php'; | ||
@@ -5,0 +13,0 @@ $parser = new WP_Block_Parser(); |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
103573
1.67%