From 79a38a1ebb075bf9da555b5a9567b6a27a006268 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:35:03 +0000 Subject: [PATCH] Implement EscapeSequence --- src/Components/Inlines/EscapeSequence.php | 51 +++++++++++++++++++++++ src/Parsedown.php | 10 ----- 2 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/Components/Inlines/EscapeSequence.php diff --git a/src/Components/Inlines/EscapeSequence.php b/src/Components/Inlines/EscapeSequence.php new file mode 100644 index 0000000..dbf55f6 --- /dev/null +++ b/src/Components/Inlines/EscapeSequence.php @@ -0,0 +1,51 @@ +#+-.!|~'; + + /** @var string */ + private $html; + + /** + * @param string $html + */ + public function __construct($html) + { + $this->html = $html; + $this->width = 2; + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static|null + */ + public static function build(Excerpt $Excerpt, State $State) + { + if (isset($Excerpt->text()[1]) and \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) { + return new self($c); + } + + return null; + } + + /** + * @return RawHtml + */ + public function stateRenderable(Parsedown $_) + { + return new RawHtml($this->html); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index 55c130c..a2e666f 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,16 +411,6 @@ class Parsedown return $Elements; } - protected function inlineEscapeSequence($Excerpt) - { - if (isset($Excerpt['text'][1]) and \in_array($Excerpt['text'][1], $this->specialCharacters, true)) { - return [ - 'element' => ['rawHtml' => $Excerpt['text'][1]], - 'extent' => 2, - ]; - } - } - protected function inlineImage($Excerpt) { if (! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') {