From db1d0a4999a1b8370e844d1659cf368a90e9c9e9 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:36:55 +0000 Subject: [PATCH] Implement Strikethrough --- src/Components/Inlines/Strikethrough.php | 67 ++++++++++++++++++++++++ src/Parsedown.php | 21 -------- 2 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 src/Components/Inlines/Strikethrough.php diff --git a/src/Components/Inlines/Strikethrough.php b/src/Components/Inlines/Strikethrough.php new file mode 100644 index 0000000..93ac2aa --- /dev/null +++ b/src/Components/Inlines/Strikethrough.php @@ -0,0 +1,67 @@ +text = $text; + $this->width = $width; + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static|null + */ + public static function build(Excerpt $Excerpt, State $State) + { + $text = $Excerpt->text(); + + if (\strlen($text) < 2) { + return null; + } + + if ($text[1] === '~' and \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) { + return new self($matches[1], \strlen($matches[0])); + } + + return null; + } + + /** + * @return Handler + */ + public function stateRenderable(Parsedown $Parsedown) + { + return new Handler( + /** @return Element */ + function (State $State) use ($Parsedown) { + return new Element( + 'del', + [], + $State->applyTo($Parsedown->lineElements($this->text)) + ); + } + ); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index b91b5bf..b731ae3 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,27 +411,6 @@ class Parsedown return $Elements; } - protected function inlineStrikethrough($Excerpt) - { - if (! isset($Excerpt['text'][1])) { - return; - } - - if ($Excerpt['text'][1] === '~' and \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) { - return [ - 'extent' => \strlen($matches[0]), - 'element' => [ - 'name' => 'del', - 'handler' => [ - 'function' => 'lineElements', - 'argument' => $matches[1], - 'destination' => 'elements', - ] - ], - ]; - } - } - protected function inlineUrl($Excerpt) { if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') {