From 5def46b716dec47737f8fbe23bb7837a89c47205 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 26 Jun 2017 19:05:16 +0200 Subject: [PATCH 1/5] Parser: Parse tag and These tags are officially supported by WordPress and are an exception with the concept of blocks. They contain structural data and yet they are just HTML comments without any further indication. The "more" tag supports an optional custom text string and if it is immediately followed by the "no teaser" tag then that contains additional information. In this change we parse those tags and combine them into a single "more" block with attributes of the custom text and whether or not the `noTeaser` option has been selected. --- blocks/api/post.pegjs | 17 ++++++++++++++++- post-content.js | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/blocks/api/post.pegjs b/blocks/api/post.pegjs index 97d6372e514cae..c3d0ddb28db0f8 100644 --- a/blocks/api/post.pegjs +++ b/blocks/api/post.pegjs @@ -22,10 +22,25 @@ WP_Block_List = WP_Block* WP_Block - = WP_Block_Void + = WP_Tag_More + / WP_Block_Void / WP_Block_Balanced / WP_Block_Html +WP_Tag_More + = "") .)+) { return text })? WS* "-->" noTeaser:(WS* WP_Tag_NoTeaser)? + { return { + blockName: 'wp:core/more', + attrs: { + customText: customText, + noTeaser: !! noTeaser + }, + rawContent: '' + } } + +WP_Tag_NoTeaser + = "" + WP_Block_Void = "', + '', + '', + '', '

The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of pieces of content—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you\'ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.

', '', From 065d158700d2c80e06da6106794e57039a3d9b7b Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 26 Jun 2017 19:26:36 +0200 Subject: [PATCH 2/5] Remove allowance for whitespace in noteaser tag --- blocks/api/post.pegjs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/blocks/api/post.pegjs b/blocks/api/post.pegjs index c3d0ddb28db0f8..ad64391b05c0d9 100644 --- a/blocks/api/post.pegjs +++ b/blocks/api/post.pegjs @@ -28,7 +28,7 @@ WP_Block / WP_Block_Html WP_Tag_More - = "") .)+) { return text })? WS* "-->" noTeaser:(WS* WP_Tag_NoTeaser)? + = "") .)+) { return text })? WS* "-->" noTeaser:(WS* "")? { return { blockName: 'wp:core/more', attrs: { @@ -38,9 +38,6 @@ WP_Tag_More rawContent: '' } } -WP_Tag_NoTeaser - = "" - WP_Block_Void = "${ saveAttributes.noTeaser ? '\n' : '' }`; + } + const serializedAttributes = ! isEmpty( saveAttributes ) ? serializeAttributes( saveAttributes ) + ' ' : ''; From d5eab31f4c97c8ce5d84ec50a37df836362f9a95 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 3 Jul 2017 14:44:30 +0200 Subject: [PATCH 4/5] appease the angry linter --- lib/parser.php | 518 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 398 insertions(+), 120 deletions(-) diff --git a/lib/parser.php b/lib/parser.php index b135f0870852e2..65e917ca647462 100644 --- a/lib/parser.php +++ b/lib/parser.php @@ -218,43 +218,56 @@ private function peg_buildException($message, $expected, $pos) { private $peg_c27; private $peg_c28; private $peg_c29; - - private function peg_f0($blockName, $a) { return $a; } - private function peg_f1($blockName, $attrs) { + private $peg_c30; + private $peg_c31; + private $peg_c32; + private $peg_c33; + + private function peg_f0($text) { return text } + private function peg_f1($customText, $noTeaser) { return { + blockName: 'wp:core/more', + attrs: { + customText: customText, + noTeaser: !! noTeaser + }, + rawContent: '' + } } + private function peg_f2($blockName, $a) { return $a; } + private function peg_f3($blockName, $attrs) { return array( 'blockName' => $blockName, 'attrs' => $attrs, 'rawContent' => '', ); } - private function peg_f2($s, $c) { return $c; } - private function peg_f3($s, $ts, $e) { return $s['blockName'] === $e['blockName']; } - private function peg_f4($s, $ts, $e) { + private function peg_f4($s, $c) { return $c; } + private function peg_f5($s, $ts, $e) { return $s['blockName'] === $e['blockName']; } + private function peg_f6($s, $ts, $e) { return array( 'blockName' => $s['blockName'], 'attrs' => $s['attrs'], 'rawContent' => implode( '', $ts ), ); } - private function peg_f5($c) { return $c; } - private function peg_f6($ts) { + private function peg_f7($c) { return $c; } + private function peg_f8($ts) { return array( 'attrs' => array(), 'rawContent' => implode( '', $ts ), ); } - private function peg_f7($blockName, $attrs) { + private function peg_f9($blockName, $attrs) { return array( 'blockName' => $blockName, 'attrs' => $attrs, ); } - private function peg_f8($blockName) { + private function peg_f10($blockName) { return array( 'blockName' => $blockName, ); } - private function peg_f9($attrs) { return json_decode( $attrs, true ); } + private function peg_f11($attrs) { return json_decode( $attrs, true ); } private function peg_parseDocument() { @@ -277,12 +290,273 @@ private function peg_parseWP_Block_List() { private function peg_parseWP_Block() { - $s0 = $this->peg_parseWP_Block_Void(); + $s0 = $this->peg_parseWP_Tag_More(); if ($s0 === $this->peg_FAILED) { - $s0 = $this->peg_parseWP_Block_Balanced(); + $s0 = $this->peg_parseWP_Block_Void(); if ($s0 === $this->peg_FAILED) { - $s0 = $this->peg_parseWP_Block_Html(); + $s0 = $this->peg_parseWP_Block_Balanced(); + if ($s0 === $this->peg_FAILED) { + $s0 = $this->peg_parseWP_Block_Html(); + } + } + } + + return $s0; + } + + private function peg_parseWP_Tag_More() { + + $s0 = $this->peg_currPos; + if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c0) { + $s1 = $this->peg_c0; + $this->peg_currPos += 4; + } else { + $s1 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c1); } + } + if ($s1 !== $this->peg_FAILED) { + $s2 = array(); + $s3 = $this->peg_parseWS(); + while ($s3 !== $this->peg_FAILED) { + $s2[] = $s3; + $s3 = $this->peg_parseWS(); + } + if ($s2 !== $this->peg_FAILED) { + if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c2) { + $s3 = $this->peg_c2; + $this->peg_currPos += 4; + } else { + $s3 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c3); } + } + if ($s3 !== $this->peg_FAILED) { + $s4 = $this->peg_currPos; + $s5 = array(); + $s6 = $this->peg_parseWS(); + if ($s6 !== $this->peg_FAILED) { + while ($s6 !== $this->peg_FAILED) { + $s5[] = $s6; + $s6 = $this->peg_parseWS(); + } + } else { + $s5 = $this->peg_FAILED; + } + if ($s5 !== $this->peg_FAILED) { + $s6 = $this->peg_currPos; + $s7 = array(); + $s8 = $this->peg_currPos; + $s9 = $this->peg_currPos; + $this->peg_silentFails++; + $s10 = $this->peg_currPos; + $s11 = array(); + $s12 = $this->peg_parseWS(); + while ($s12 !== $this->peg_FAILED) { + $s11[] = $s12; + $s12 = $this->peg_parseWS(); + } + if ($s11 !== $this->peg_FAILED) { + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s12 = $this->peg_c4; + $this->peg_currPos += 3; + } else { + $s12 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } + } + if ($s12 !== $this->peg_FAILED) { + $s11 = array($s11, $s12); + $s10 = $s11; + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + $this->peg_silentFails--; + if ($s10 === $this->peg_FAILED) { + $s9 = null; + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + if ($s9 !== $this->peg_FAILED) { + if (mb_strlen($this->input, "UTF-8") > $this->peg_currPos) { + $s10 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); + $this->peg_currPos++; + } else { + $s10 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c6); } + } + if ($s10 !== $this->peg_FAILED) { + $s9 = array($s9, $s10); + $s8 = $s9; + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + if ($s8 !== $this->peg_FAILED) { + while ($s8 !== $this->peg_FAILED) { + $s7[] = $s8; + $s8 = $this->peg_currPos; + $s9 = $this->peg_currPos; + $this->peg_silentFails++; + $s10 = $this->peg_currPos; + $s11 = array(); + $s12 = $this->peg_parseWS(); + while ($s12 !== $this->peg_FAILED) { + $s11[] = $s12; + $s12 = $this->peg_parseWS(); + } + if ($s11 !== $this->peg_FAILED) { + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s12 = $this->peg_c4; + $this->peg_currPos += 3; + } else { + $s12 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } + } + if ($s12 !== $this->peg_FAILED) { + $s11 = array($s11, $s12); + $s10 = $s11; + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + $this->peg_silentFails--; + if ($s10 === $this->peg_FAILED) { + $s9 = null; + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + if ($s9 !== $this->peg_FAILED) { + if (mb_strlen($this->input, "UTF-8") > $this->peg_currPos) { + $s10 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); + $this->peg_currPos++; + } else { + $s10 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c6); } + } + if ($s10 !== $this->peg_FAILED) { + $s9 = array($s9, $s10); + $s8 = $s9; + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + } + } else { + $s7 = $this->peg_FAILED; + } + if ($s7 !== $this->peg_FAILED) { + $s6 = mb_substr($this->input, $s6, $this->peg_currPos - $s6, "UTF-8"); + } else { + $s6 = $s7; + } + if ($s6 !== $this->peg_FAILED) { + $this->peg_reportedPos = $s4; + $s5 = $this->peg_f0($s6); + $s4 = $s5; + } else { + $this->peg_currPos = $s4; + $s4 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s4; + $s4 = $this->peg_FAILED; + } + if ($s4 === $this->peg_FAILED) { + $s4 = null; + } + if ($s4 !== $this->peg_FAILED) { + $s5 = array(); + $s6 = $this->peg_parseWS(); + while ($s6 !== $this->peg_FAILED) { + $s5[] = $s6; + $s6 = $this->peg_parseWS(); + } + if ($s5 !== $this->peg_FAILED) { + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s6 = $this->peg_c4; + $this->peg_currPos += 3; + } else { + $s6 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } + } + if ($s6 !== $this->peg_FAILED) { + $s7 = $this->peg_currPos; + $s8 = array(); + $s9 = $this->peg_parseWS(); + while ($s9 !== $this->peg_FAILED) { + $s8[] = $s9; + $s9 = $this->peg_parseWS(); + } + if ($s8 !== $this->peg_FAILED) { + if (mb_substr($this->input, $this->peg_currPos, 15, "UTF-8") === $this->peg_c7) { + $s9 = $this->peg_c7; + $this->peg_currPos += 15; + } else { + $s9 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c8); } + } + if ($s9 !== $this->peg_FAILED) { + $s8 = array($s8, $s9); + $s7 = $s8; + } else { + $this->peg_currPos = $s7; + $s7 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s7; + $s7 = $this->peg_FAILED; + } + if ($s7 === $this->peg_FAILED) { + $s7 = null; + } + if ($s7 !== $this->peg_FAILED) { + $this->peg_reportedPos = $s0; + $s1 = $this->peg_f1($s4, $s7); + $s0 = $s1; + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; } + } else { + $this->peg_currPos = $s0; + $s0 = $this->peg_FAILED; } return $s0; @@ -310,12 +584,12 @@ private function peg_parseWP_Block_Void() { $s2 = $this->peg_FAILED; } if ($s2 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c2) { - $s3 = $this->peg_c2; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c9) { + $s3 = $this->peg_c9; $this->peg_currPos += 3; } else { $s3 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c3); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c10); } } if ($s3 !== $this->peg_FAILED) { $s4 = $this->peg_parseWP_Block_Name(); @@ -346,7 +620,7 @@ private function peg_parseWP_Block_Void() { } if ($s8 !== $this->peg_FAILED) { $this->peg_reportedPos = $s6; - $s7 = $this->peg_f0($s4, $s7); + $s7 = $this->peg_f2($s4, $s7); $s6 = $s7; } else { $this->peg_currPos = $s6; @@ -360,16 +634,16 @@ private function peg_parseWP_Block_Void() { $s6 = null; } if ($s6 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c4) { - $s7 = $this->peg_c4; + if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c11) { + $s7 = $this->peg_c11; $this->peg_currPos += 4; } else { $s7 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c12); } } if ($s7 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f1($s4, $s6); + $s1 = $this->peg_f3($s4, $s6); $s0 = $s1; } else { $this->peg_currPos = $s0; @@ -424,7 +698,7 @@ private function peg_parseWP_Block_Balanced() { $s5 = $this->peg_parseAny(); if ($s5 !== $this->peg_FAILED) { $this->peg_reportedPos = $s3; - $s4 = $this->peg_f2($s1, $s5); + $s4 = $this->peg_f4($s1, $s5); $s3 = $s4; } else { $this->peg_currPos = $s3; @@ -451,7 +725,7 @@ private function peg_parseWP_Block_Balanced() { $s5 = $this->peg_parseAny(); if ($s5 !== $this->peg_FAILED) { $this->peg_reportedPos = $s3; - $s4 = $this->peg_f2($s1, $s5); + $s4 = $this->peg_f4($s1, $s5); $s3 = $s4; } else { $this->peg_currPos = $s3; @@ -466,7 +740,7 @@ private function peg_parseWP_Block_Balanced() { $s3 = $this->peg_parseWP_Block_End(); if ($s3 !== $this->peg_FAILED) { $this->peg_reportedPos = $this->peg_currPos; - $s4 = $this->peg_f3($s1, $s2, $s3); + $s4 = $this->peg_f5($s1, $s2, $s3); if ($s4) { $s4 = null; } else { @@ -474,7 +748,7 @@ private function peg_parseWP_Block_Balanced() { } if ($s4 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f4($s1, $s2, $s3); + $s1 = $this->peg_f6($s1, $s2, $s3); $s0 = $s1; } else { $this->peg_currPos = $s0; @@ -526,7 +800,7 @@ private function peg_parseWP_Block_Html() { $s5 = $this->peg_parseAny(); if ($s5 !== $this->peg_FAILED) { $this->peg_reportedPos = $s2; - $s3 = $this->peg_f5($s5); + $s3 = $this->peg_f7($s5); $s2 = $s3; } else { $this->peg_currPos = $s2; @@ -569,7 +843,7 @@ private function peg_parseWP_Block_Html() { $s5 = $this->peg_parseAny(); if ($s5 !== $this->peg_FAILED) { $this->peg_reportedPos = $s2; - $s3 = $this->peg_f5($s5); + $s3 = $this->peg_f7($s5); $s2 = $s3; } else { $this->peg_currPos = $s2; @@ -589,7 +863,7 @@ private function peg_parseWP_Block_Html() { } if ($s1 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f6($s1); + $s1 = $this->peg_f8($s1); } $s0 = $s1; @@ -618,12 +892,12 @@ private function peg_parseWP_Block_Start() { $s2 = $this->peg_FAILED; } if ($s2 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c2) { - $s3 = $this->peg_c2; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c9) { + $s3 = $this->peg_c9; $this->peg_currPos += 3; } else { $s3 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c3); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c10); } } if ($s3 !== $this->peg_FAILED) { $s4 = $this->peg_parseWP_Block_Name(); @@ -654,7 +928,7 @@ private function peg_parseWP_Block_Start() { } if ($s8 !== $this->peg_FAILED) { $this->peg_reportedPos = $s6; - $s7 = $this->peg_f0($s4, $s7); + $s7 = $this->peg_f2($s4, $s7); $s6 = $s7; } else { $this->peg_currPos = $s6; @@ -668,16 +942,16 @@ private function peg_parseWP_Block_Start() { $s6 = null; } if ($s6 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c6) { - $s7 = $this->peg_c6; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s7 = $this->peg_c4; $this->peg_currPos += 3; } else { $s7 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c7); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } } if ($s7 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f7($s4, $s6); + $s1 = $this->peg_f9($s4, $s6); $s0 = $s1; } else { $this->peg_currPos = $s0; @@ -733,12 +1007,12 @@ private function peg_parseWP_Block_End() { $s2 = $this->peg_FAILED; } if ($s2 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c8) { - $s3 = $this->peg_c8; + if (mb_substr($this->input, $this->peg_currPos, 4, "UTF-8") === $this->peg_c13) { + $s3 = $this->peg_c13; $this->peg_currPos += 4; } else { $s3 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c9); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c14); } } if ($s3 !== $this->peg_FAILED) { $s4 = $this->peg_parseWP_Block_Name(); @@ -754,16 +1028,16 @@ private function peg_parseWP_Block_End() { $s5 = $this->peg_FAILED; } if ($s5 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c6) { - $s6 = $this->peg_c6; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s6 = $this->peg_c4; $this->peg_currPos += 3; } else { $s6 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c7); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } } if ($s6 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f8($s4); + $s1 = $this->peg_f10($s4); $s0 = $s1; } else { $this->peg_currPos = $s0; @@ -803,12 +1077,12 @@ private function peg_parseWP_Block_Name() { $s4 = $this->peg_parseASCII_AlphaNumeric(); if ($s4 === $this->peg_FAILED) { $s4 = $this->peg_currPos; - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c10) { - $s5 = $this->peg_c10; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c15) { + $s5 = $this->peg_c15; $this->peg_currPos++; } else { $s5 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c11); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c16); } } if ($s5 !== $this->peg_FAILED) { $s6 = $this->peg_parseASCII_AlphaNumeric(); @@ -829,12 +1103,12 @@ private function peg_parseWP_Block_Name() { $s4 = $this->peg_parseASCII_AlphaNumeric(); if ($s4 === $this->peg_FAILED) { $s4 = $this->peg_currPos; - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c10) { - $s5 = $this->peg_c10; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c15) { + $s5 = $this->peg_c15; $this->peg_currPos++; } else { $s5 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c11); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c16); } } if ($s5 !== $this->peg_FAILED) { $s6 = $this->peg_parseASCII_AlphaNumeric(); @@ -876,12 +1150,12 @@ private function peg_parseWP_Block_Attributes() { $s0 = $this->peg_currPos; $s1 = $this->peg_currPos; $s2 = $this->peg_currPos; - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c12) { - $s3 = $this->peg_c12; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c17) { + $s3 = $this->peg_c17; $this->peg_currPos++; } else { $s3 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c13); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c18); } } if ($s3 !== $this->peg_FAILED) { $s4 = array(); @@ -889,12 +1163,12 @@ private function peg_parseWP_Block_Attributes() { $s6 = $this->peg_currPos; $this->peg_silentFails++; $s7 = $this->peg_currPos; - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c14) { - $s8 = $this->peg_c14; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c19) { + $s8 = $this->peg_c19; $this->peg_currPos++; } else { $s8 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c15); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c20); } } if ($s8 !== $this->peg_FAILED) { $s9 = array(); @@ -908,25 +1182,25 @@ private function peg_parseWP_Block_Attributes() { $s9 = $this->peg_FAILED; } if ($s9 !== $this->peg_FAILED) { - $s10 = $this->peg_c16; + $s10 = $this->peg_c21; if ($s10 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c10) { - $s11 = $this->peg_c10; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c15) { + $s11 = $this->peg_c15; $this->peg_currPos++; } else { $s11 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c11); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c16); } } if ($s11 === $this->peg_FAILED) { $s11 = null; } if ($s11 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c6) { - $s12 = $this->peg_c6; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s12 = $this->peg_c4; $this->peg_currPos += 3; } else { $s12 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c7); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } } if ($s12 !== $this->peg_FAILED) { $s8 = array($s8, $s9, $s10, $s11, $s12); @@ -964,7 +1238,7 @@ private function peg_parseWP_Block_Attributes() { $this->peg_currPos++; } else { $s7 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c17); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c6); } } if ($s7 !== $this->peg_FAILED) { $s6 = array($s6, $s7); @@ -983,12 +1257,12 @@ private function peg_parseWP_Block_Attributes() { $s6 = $this->peg_currPos; $this->peg_silentFails++; $s7 = $this->peg_currPos; - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c14) { - $s8 = $this->peg_c14; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c19) { + $s8 = $this->peg_c19; $this->peg_currPos++; } else { $s8 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c15); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c20); } } if ($s8 !== $this->peg_FAILED) { $s9 = array(); @@ -1002,25 +1276,25 @@ private function peg_parseWP_Block_Attributes() { $s9 = $this->peg_FAILED; } if ($s9 !== $this->peg_FAILED) { - $s10 = $this->peg_c16; + $s10 = $this->peg_c21; if ($s10 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c10) { - $s11 = $this->peg_c10; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c15) { + $s11 = $this->peg_c15; $this->peg_currPos++; } else { $s11 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c11); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c16); } } if ($s11 === $this->peg_FAILED) { $s11 = null; } if ($s11 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c6) { - $s12 = $this->peg_c6; + if (mb_substr($this->input, $this->peg_currPos, 3, "UTF-8") === $this->peg_c4) { + $s12 = $this->peg_c4; $this->peg_currPos += 3; } else { $s12 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c7); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c5); } } if ($s12 !== $this->peg_FAILED) { $s8 = array($s8, $s9, $s10, $s11, $s12); @@ -1058,7 +1332,7 @@ private function peg_parseWP_Block_Attributes() { $this->peg_currPos++; } else { $s7 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c17); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c6); } } if ($s7 !== $this->peg_FAILED) { $s6 = array($s6, $s7); @@ -1073,12 +1347,12 @@ private function peg_parseWP_Block_Attributes() { } } if ($s4 !== $this->peg_FAILED) { - if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c14) { - $s5 = $this->peg_c14; + if (mb_substr($this->input, $this->peg_currPos, 1, "UTF-8") === $this->peg_c19) { + $s5 = $this->peg_c19; $this->peg_currPos++; } else { $s5 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c15); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c20); } } if ($s5 !== $this->peg_FAILED) { $s3 = array($s3, $s4, $s5); @@ -1102,7 +1376,7 @@ private function peg_parseWP_Block_Attributes() { } if ($s1 !== $this->peg_FAILED) { $this->peg_reportedPos = $s0; - $s1 = $this->peg_f9($s1); + $s1 = $this->peg_f11($s1); } $s0 = $s1; @@ -1124,12 +1398,12 @@ private function peg_parseASCII_AlphaNumeric() { private function peg_parseASCII_Letter() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c18, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c22, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c19); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c23); } } return $s0; @@ -1137,12 +1411,12 @@ private function peg_parseASCII_Letter() { private function peg_parseASCII_Digit() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c20, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c24, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c21); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c25); } } return $s0; @@ -1150,12 +1424,12 @@ private function peg_parseASCII_Digit() { private function peg_parseSpecial_Chars() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c22, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c26, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c23); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c27); } } return $s0; @@ -1163,12 +1437,12 @@ private function peg_parseSpecial_Chars() { private function peg_parseWS() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c24, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c28, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c25); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c29); } } return $s0; @@ -1176,12 +1450,12 @@ private function peg_parseWS() { private function peg_parseNewline() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c26, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c30, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c27); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c31); } } return $s0; @@ -1189,12 +1463,12 @@ private function peg_parseNewline() { private function peg_parse_() { - if (Gutenberg_PEG_peg_regex_test($this->peg_c28, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { + if (Gutenberg_PEG_peg_regex_test($this->peg_c32, mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"))) { $s0 = mb_substr($this->input, $this->peg_currPos, 1, "UTF-8"); $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c29); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c33); } } return $s0; @@ -1223,7 +1497,7 @@ private function peg_parseAny() { $this->peg_currPos++; } else { $s0 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c17); } + if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c6); } } return $s0; @@ -1240,34 +1514,38 @@ public function parse($input) { $this->peg_FAILED = new stdClass; $this->peg_c0 = ""; - $this->peg_c5 = array( "type" => "literal", "value" => "/-->", "description" => "\"/-->\"" ); - $this->peg_c6 = "-->"; - $this->peg_c7 = array( "type" => "literal", "value" => "-->", "description" => "\"-->\"" ); - $this->peg_c8 = "/wp:"; - $this->peg_c9 = array( "type" => "literal", "value" => "/wp:", "description" => "\"/wp:\"" ); - $this->peg_c10 = "/"; - $this->peg_c11 = array( "type" => "literal", "value" => "/", "description" => "\"/\"" ); - $this->peg_c12 = "{"; - $this->peg_c13 = array( "type" => "literal", "value" => "{", "description" => "\"{\"" ); - $this->peg_c14 = "}"; - $this->peg_c15 = array( "type" => "literal", "value" => "}", "description" => "\"}\"" ); - $this->peg_c16 = ""; - $this->peg_c17 = array("type" => "any", "description" => "any character" ); - $this->peg_c18 = "/^[a-zA-Z]/"; - $this->peg_c19 = array( "type" => "class", "value" => "[a-zA-Z]", "description" => "[a-zA-Z]" ); - $this->peg_c20 = "/^[0-9]/"; - $this->peg_c21 = array( "type" => "class", "value" => "[0-9]", "description" => "[0-9]" ); - $this->peg_c22 = "/^[-_]/"; - $this->peg_c23 = array( "type" => "class", "value" => "[-_]", "description" => "[-_]" ); - $this->peg_c24 = "/^[ \\t\\r\\n]/"; - $this->peg_c25 = array( "type" => "class", "value" => "[ \t\r\n]", "description" => "[ \t\r\n]" ); - $this->peg_c26 = "/^[\\r\\n]/"; - $this->peg_c27 = array( "type" => "class", "value" => "[\r\n]", "description" => "[\r\n]" ); - $this->peg_c28 = "/^[ \\t]/"; - $this->peg_c29 = array( "type" => "class", "value" => "[ \t]", "description" => "[ \t]" ); + $this->peg_c2 = "more"; + $this->peg_c3 = array( "type" => "literal", "value" => "more", "description" => "\"more\"" ); + $this->peg_c4 = "-->"; + $this->peg_c5 = array( "type" => "literal", "value" => "-->", "description" => "\"-->\"" ); + $this->peg_c6 = array("type" => "any", "description" => "any character" ); + $this->peg_c7 = ""; + $this->peg_c8 = array( "type" => "literal", "value" => "", "description" => "\"\"" ); + $this->peg_c9 = "wp:"; + $this->peg_c10 = array( "type" => "literal", "value" => "wp:", "description" => "\"wp:\"" ); + $this->peg_c11 = "/-->"; + $this->peg_c12 = array( "type" => "literal", "value" => "/-->", "description" => "\"/-->\"" ); + $this->peg_c13 = "/wp:"; + $this->peg_c14 = array( "type" => "literal", "value" => "/wp:", "description" => "\"/wp:\"" ); + $this->peg_c15 = "/"; + $this->peg_c16 = array( "type" => "literal", "value" => "/", "description" => "\"/\"" ); + $this->peg_c17 = "{"; + $this->peg_c18 = array( "type" => "literal", "value" => "{", "description" => "\"{\"" ); + $this->peg_c19 = "}"; + $this->peg_c20 = array( "type" => "literal", "value" => "}", "description" => "\"}\"" ); + $this->peg_c21 = ""; + $this->peg_c22 = "/^[a-zA-Z]/"; + $this->peg_c23 = array( "type" => "class", "value" => "[a-zA-Z]", "description" => "[a-zA-Z]" ); + $this->peg_c24 = "/^[0-9]/"; + $this->peg_c25 = array( "type" => "class", "value" => "[0-9]", "description" => "[0-9]" ); + $this->peg_c26 = "/^[-_]/"; + $this->peg_c27 = array( "type" => "class", "value" => "[-_]", "description" => "[-_]" ); + $this->peg_c28 = "/^[ \\t\\r\\n]/"; + $this->peg_c29 = array( "type" => "class", "value" => "[ \t\r\n]", "description" => "[ \t\r\n]" ); + $this->peg_c30 = "/^[\\r\\n]/"; + $this->peg_c31 = array( "type" => "class", "value" => "[\r\n]", "description" => "[\r\n]" ); + $this->peg_c32 = "/^[ \\t]/"; + $this->peg_c33 = array( "type" => "class", "value" => "[ \t]", "description" => "[ \t]" ); $peg_startRuleFunctions = array( 'Document' => array($this, "peg_parseDocument") ); $peg_startRuleFunction = array($this, "peg_parseDocument"); From 6a4ca435dda0d0611e95d2f4d4bf0eff89d7ef80 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 3 Jul 2017 15:08:00 +0200 Subject: [PATCH 5/5] appease the angry linter --- blocks/api/post.pegjs | 29 ++++++++++++++++++++--------- lib/parser.php | 20 +++++++++++--------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/blocks/api/post.pegjs b/blocks/api/post.pegjs index ad64391b05c0d9..033374a981303d 100644 --- a/blocks/api/post.pegjs +++ b/blocks/api/post.pegjs @@ -28,15 +28,26 @@ WP_Block / WP_Block_Html WP_Tag_More - = "") .)+) { return text })? WS* "-->" noTeaser:(WS* "")? - { return { - blockName: 'wp:core/more', - attrs: { - customText: customText, - noTeaser: !! noTeaser - }, - rawContent: '' - } } + = "") .)+) { /** **/ return text })? WS* "-->" noTeaser:(WS* "")? + { /** 'wp:core/more', + 'attrs' => array( + 'customText' => $customText, + 'noTeaser' => (bool) $noTeaser + ), + 'rawContent' => '' + ); + ?> **/ + return { + blockName: 'wp:core/more', + attrs: { + customText: customText, + noTeaser: !! noTeaser + }, + rawContent: '' + } + } WP_Block_Void = "