From 18e239fba16623185794d2e820fbfd1336ed374b Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:31:18 +0000 Subject: [PATCH] Implement Paragraph --- src/Components/Blocks/Paragraph.php | 78 +++++++++++++++++++++++++++++ src/Parsedown.php | 30 ----------- 2 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 src/Components/Blocks/Paragraph.php diff --git a/src/Components/Blocks/Paragraph.php b/src/Components/Blocks/Paragraph.php new file mode 100644 index 0000000..a1e7873 --- /dev/null +++ b/src/Components/Blocks/Paragraph.php @@ -0,0 +1,78 @@ +text = $text; + } + + /** + * @param Context $Context + * @param Block|null $Block + * @param State|null $State + * @return static + */ + public static function build( + Context $Context, + Block $Block = null, + State $State = null + ) { + return new self($Context->line()->text()); + } + + /** + * @param Context $Context + * @return self|null + */ + public function continue(Context $Context) + { + if ($this->interrupted) { + return null; + } + + return new self($this->text . "\n" . $Context->line()->text()); + } + + /** @return string */ + public function text() + { + return $this->text; + } + + /** + * @return Handler + */ + public function stateRenderable(Parsedown $Parsedown) + { + return new Handler( + /** @return Element */ + function (State $State) use ($Parsedown) { + return new Element( + 'p', + [], + $State->applyTo($Parsedown->lineElements($this->text)) + ); + } + ); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index 09b6077..b57b49c 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -288,36 +288,6 @@ class Parsedown return \method_exists($this, 'block' . $Type . 'Complete'); } - # - # ~ - # - - protected function paragraph(Context $Context) - { - return [ - 'type' => 'Paragraph', - 'element' => [ - 'name' => 'p', - 'handler' => [ - 'function' => 'lineElements', - 'argument' => $Context->line()->text(), - 'destination' => 'elements', - ], - ], - ]; - } - - protected function paragraphContinue(Context $Context, array $Block) - { - if (isset($Block['interrupted'])) { - return; - } - - $Block['element']['handler']['argument'] .= "\n".$Context->line()->text(); - - return $Block; - } - # # Inline Elements #