From f256352f5355b3127f6b1ceba9db0a61637a0558 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:36:32 +0000 Subject: [PATCH] Implement SpecialCharacter --- src/Components/Inlines/SpecialCharacter.php | 54 +++++++++++++++++++++ src/Parsedown.php | 14 ------ 2 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 src/Components/Inlines/SpecialCharacter.php diff --git a/src/Components/Inlines/SpecialCharacter.php b/src/Components/Inlines/SpecialCharacter.php new file mode 100644 index 0000000..f53faab --- /dev/null +++ b/src/Components/Inlines/SpecialCharacter.php @@ -0,0 +1,54 @@ +charCodeHtml = $charCodeHtml; + $this->width = \strlen($charCodeHtml) + 2; + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static|null + */ + public static function build(Excerpt $Excerpt, State $State) + { + if (\substr($Excerpt->text(), 1, 1) !== ' ' and \strpos($Excerpt->text(), ';') !== false + and \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt->text(), $matches) + ) { + return new self($matches[1]); + } + + return null; + } + + /** + * @return RawHtml + */ + public function stateRenderable(Parsedown $_) + { + return new RawHtml( + '&' . (new Text($this->charCodeHtml))->getHtml() . ';' + ); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index 63b91ce..b91b5bf 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,20 +411,6 @@ class Parsedown return $Elements; } - protected function inlineSpecialCharacter($Excerpt) - { - if (\substr($Excerpt['text'], 1, 1) !== ' ' and \strpos($Excerpt['text'], ';') !== false - and \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches) - ) { - return [ - 'element' => ['rawHtml' => '&' . $matches[1] . ';'], - 'extent' => \strlen($matches[0]), - ]; - } - - return; - } - protected function inlineStrikethrough($Excerpt) { if (! isset($Excerpt['text'][1])) {