From 497045d25b2a35daef129160c2dde7fcad36c54e Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 20 Jan 2019 02:33:45 +0000 Subject: [PATCH] Implement Code --- src/Components/Inlines/Code.php | 61 +++++++++++++++++++++++++++++++++ src/Parsedown.php | 18 ---------- 2 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 src/Components/Inlines/Code.php diff --git a/src/Components/Inlines/Code.php b/src/Components/Inlines/Code.php new file mode 100644 index 0000000..cde7f43 --- /dev/null +++ b/src/Components/Inlines/Code.php @@ -0,0 +1,61 @@ +text = $text; + $this->width = $width; + } + + /** + * @param Excerpt $Excerpt + * @param State $State + * @return static|null + */ + public static function build(Excerpt $Excerpt, State $State) + { + $marker = $Excerpt->text()[0]; + + if ($marker !== '`') { + return null; + } + + if (\preg_match( + '/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(?text(), + $matches + )) { + $text = \preg_replace('/[ ]*+\n/', ' ', $matches[2]); + + return new self($text, \strlen($matches[0])); + } + } + + /** + * @return Element + */ + public function stateRenderable(Parsedown $_) + { + return new Element('code', [], [new Text($this->text)]); + } +} diff --git a/src/Parsedown.php b/src/Parsedown.php index e02afd1..e4f57eb 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -411,24 +411,6 @@ class Parsedown return $Elements; } - protected function inlineCode($Excerpt) - { - $marker = $Excerpt['text'][0]; - - if (\preg_match('/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(? \strlen($matches[0]), - 'element' => [ - 'name' => 'code', - 'text' => $text, - ], - ]; - } - } - protected function inlineEmailTag($Excerpt) { $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';