From dd4b3d9ebb85c9bc8138212fd7cb207ab154f626 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 19 Jul 2021 17:50:21 +0200 Subject: Add and use new parser/transformer classes Classes: * Parsers\ArgumentParser * Parsers\EmoticonParser * Parsers\MarkdownParser Interfaces: * Parsers\ParserInterface --- core/namespace/Parsers/MarkdownParser.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 core/namespace/Parsers/MarkdownParser.php (limited to 'core/namespace/Parsers/MarkdownParser.php') diff --git a/core/namespace/Parsers/MarkdownParser.php b/core/namespace/Parsers/MarkdownParser.php new file mode 100644 index 0000000..27a18ad --- /dev/null +++ b/core/namespace/Parsers/MarkdownParser.php @@ -0,0 +1,37 @@ +Parsedown = new Parsedown(); + $this->Parsedown->setUrlsLinked(FALSE); + } + + #=========================================================================== + # Parse Markdown (currently only images) + #=========================================================================== + public function parse(string $text): array { + $image = '#\!\[(.*)\]\((.*)(?:\s[\'"](.*)[\'"])?\)#U'; + + if(preg_match_all($image, $text, $matches)) { + $data['img']['src'] = $matches[2]; + $data['img']['alt'] = $matches[1]; + $data['img']['title'] = $matches[3]; + } + + return $data ?? []; + } + + #=========================================================================== + # Transform Markdown to HTML + #=========================================================================== + public function transform(string $text): string { + return $this->Parsedown->text($text); + } +} -- cgit v1.2.3