diff --git a/src/Components/Blocks/BlockQuote.php b/src/Components/Blocks/BlockQuote.php new file mode 100644 index 0000000..f834e6c --- /dev/null +++ b/src/Components/Blocks/BlockQuote.php @@ -0,0 +1,113 @@ +Lines = $Lines; + } + + /** + * @param Context $Context + * @param Block|null $Block + * @param State|null $State + * @return static|null + */ + public static function build( + Context $Context, + Block $Block = null, + State $State = null + ) { + if (\preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) { + $indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]); + + $recoveredSpaces = 0; + if (\strlen($matches[1]) === 2 && \substr($matches[1], 1, 1) === "\t") { + $recoveredSpaces = Line::tabShortage(2, $Context->line()->indentOffset() + $Context->line()->indent()); + } + + return new self( + Lines::fromTextLines( + \str_repeat(' ', $recoveredSpaces) . $matches[2], + $indentOffset + ) + ); + } + + return null; + } + + /** + * @param Context $Context + * @return self|null + */ + public function continue(Context $Context) + { + if ($this->interrupted) { + return null; + } + + if ($Context->line()->text()[0] === '>' and \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) { + $indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]); + + $recoveredSpaces = 0; + if (\strlen($matches[1]) === 2 && \substr($matches[1], 1, 1) === "\t") { + $recoveredSpaces = Line::tabShortage(2, $Context->line()->indentOffset() + $Context->line()->indent()); + } + + $Lines = $this->Lines->appendingTextLines( + \str_repeat(' ', $recoveredSpaces) . $matches[2], + $indentOffset + ); + + return new self($Lines); + } + + if (! $Context->previousEmptyLines() > 0) { + $indentOffset = $Context->line()->indentOffset() + $Context->line()->indent(); + $Lines = $this->Lines->appendingTextLines($Context->line()->text(), $indentOffset); + + return new self($Lines); + } + + return null; + } + + /** + * @return Handler + */ + public function stateRenderable(Parsedown $Parsedown) + { + return new Handler( + /** @return Element */ + function (State $State) use ($Parsedown) { + return new Element( + 'blockquote', + [], + $State->applyTo($Parsedown->lines($this->Lines)) + ); + } + ); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index 99674e7..2ff2eae 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -636,46 +636,6 @@ class Parsedown return $Block; } - # - # Quote - - protected function blockQuote(Context $Context) - { - if (\preg_match('/^>[ ]?+(.*+)/', $Context->line()->text(), $matches)) { - $Block = [ - 'element' => [ - 'name' => 'blockquote', - 'handler' => [ - 'function' => 'linesElements', - 'argument' => Lines::fromTextLines($matches[1], 0), - 'destination' => 'elements', - ] - ], - ]; - - return $Block; - } - } - - protected function blockQuoteContinue(Context $Context, array $Block) - { - if ($Context->previousEmptyLines() > 0) { - return; - } - - if ($Context->line()->text()[0] === '>' and \preg_match('/^>[ ]?+(.*+)/', $Context->line()->text(), $matches)) { - $Block['element']['handler']['argument'] = $Block['element']['handler']['argument']->appendingTextLines($matches[1], 0); - - return $Block; - } - - if (! $Context->previousEmptyLines() > 0) { - $Block['element']['handler']['argument'] = $Block['element']['handler']['argument']->appendingTextLines($Context->line()->text(), 0); - - return $Block; - } - } - # # Rule