From a286033f52263fbce7f338dc5f539a97e477c7d2 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:37:40 +0000 Subject: [PATCH] Implement UrlTag --- src/Components/Inlines/UrlTag.php | 51 +++++++++++++++++++++++++++++++ src/Parsedown.php | 18 ----------- 2 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 src/Components/Inlines/UrlTag.php diff --git a/src/Components/Inlines/UrlTag.php b/src/Components/Inlines/UrlTag.php new file mode 100644 index 0000000..ac57d4c --- /dev/null +++ b/src/Components/Inlines/UrlTag.php @@ -0,0 +1,51 @@ +url = $url; + $this->width = $width; + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static|null + */ + public static function build(Excerpt $Excerpt, State $State) + { + if (\strpos($Excerpt->text(), '>') !== false and \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) { + return new self($matches[1], \strlen($matches[0])); + } + + return null; + } + + /** + * @return Element + */ + public function stateRenderable(Parsedown $_) + { + return new Element('a', ['href' => $this->url], [new Text($this->url)]); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index b1d1e19..35bebca 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,24 +411,6 @@ class Parsedown return $Elements; } - protected function inlineUrlTag($Excerpt) - { - if (\strpos($Excerpt['text'], '>') !== false and \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches)) { - $url = $matches[1]; - - return [ - 'extent' => \strlen($matches[0]), - 'element' => [ - 'name' => 'a', - 'text' => $url, - 'attributes' => [ - 'href' => $url, - ], - ], - ]; - } - } - # ~ protected function unmarkedText($text)