. * */ /* Name: Markdown Editor Slug: markdown-editor Category: content Url: https://www.vvveb.com Description: Change post and product page editor to markdown, automatically render as html on frontend. Author: givanz Version: 0.1 Thumb: markdown-editor.svg Author url: https://www.vvveb.com */ use Vvveb\Plugins\MarkdownEditor\System\Parsedown as Parsedown; use Vvveb\System\Event; if (! defined('V_VERSION')) { die('Invalid request!'); } class MarkdownEditorPlugin { private $parsedown; private function markdownToHtml($markdown) { //escape html tags $markdown = str_replace(['<', '>'], ['<', '>'], $markdown); //escape code blocks $markdown = preg_replace_callback('/```.*?```/ms', function ($matches) { return str_replace(['<', '>'], ['<', '>'], $matches[0]); }, $markdown); /* $markdown = preg_replace_callback('/```.*?```/ms', function ($matches) { return htmlentities($matches[0]); }, $markdown);*/ $this->parsedown = new Parsedown(); $html = $text = $this->parsedown->text($markdown); //admonitions support $html = preg_replace_callback('/
:::(\w+)<\/p>(.*?)\n
:::<\/p>/ms', function ($matches) {
$text = $matches[1];
$type = str_replace(['info', 'tip', 'note', 'caution', 'danger'], ['primary', 'info', 'secondary', 'warning', 'danger'], $text);
$icon = str_replace(['primary', 'info', 'secondary', 'warning', 'danger'], ['🛈', '💡', 'ℹ', ' 🛆', '🛇'], $type);
$message = strip_tags($matches[2], '');
return ' ' . $icon . '' . $text . '' . $message . '