From 760945008bdb24db45baa151908bd0edfed10b9c Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:33:14 +0000 Subject: [PATCH] Implement plaintext --- src/Components/Inlines/PlainText.php | 75 ++++++++++++++++++++++++++++ src/Parsedown.php | 23 --------- 2 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 src/Components/Inlines/PlainText.php diff --git a/src/Components/Inlines/PlainText.php b/src/Components/Inlines/PlainText.php new file mode 100644 index 0000000..5bb592d --- /dev/null +++ b/src/Components/Inlines/PlainText.php @@ -0,0 +1,75 @@ +text = $text; + $this->width = \strlen($text); + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static + */ + public static function build(Excerpt $Excerpt, State $State = null) + { + return new self($Excerpt->text()); + } + + /** @return string */ + public function text() + { + return $this->text; + } + + /** + * @return Handler + */ + public function stateRenderable(Parsedown $_) + { + return new Handler( + /** @return Container */ + function (State $_) { + $Renderables = []; + $text = $this->text; + + while (\preg_match('/(?:[ ]*+\\\\|[ ]{2,}+)\n/', $text, $matches, \PREG_OFFSET_CAPTURE)) { + $offset = \intval($matches[0][1]); + $before = \substr($text, 0, $offset); + $after = \substr($text, $offset + \strlen($matches[0][0])); + $Renderables[] = new Text($before); + $Renderables[] = Element::selfClosing('br', []); + $Renderables[] = new Text("\n"); + + $text = $after; + } + + $Renderables[] = new Text($text); + + return new Container($Renderables); + } + ); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index b57b49c..e02afd1 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,29 +411,6 @@ class Parsedown return $Elements; } - # - # ~ - # - - protected function inlineText($text) - { - $Inline = [ - 'extent' => \strlen($text), - 'element' => [], - ]; - - $Inline['element']['elements'] = self::pregReplaceElements( - $this->breaksEnabled ? '/[ ]*+\n/' : '/(?:[ ]*+\\\\|[ ]{2,}+)\n/', - [ - ['name' => 'br'], - ['text' => "\n"], - ], - $text - ); - - return $Inline; - } - protected function inlineCode($Excerpt) { $marker = $Excerpt['text'][0];