From: Michael Date: Fri, 27 Dec 2019 01:35:15 +0000 (+0000) Subject: Markdown: Escape some elements prior to sending them through Markdown X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f3e727570d9b4168a3eb307a3f26e3f645fb38e;p=friendica-addons.git Markdown: Escape some elements prior to sending them through Markdown --- diff --git a/markdown/markdown.php b/markdown/markdown.php index a5358d0e..9bebf64f 100644 --- a/markdown/markdown.php +++ b/markdown/markdown.php @@ -49,5 +49,25 @@ function markdown_post_local_start(App $a, &$request) { return; } + // Elements that shouldn't be parsed + $elements = ['code', 'noparse', 'nobb', 'pre']; + foreach ($elements as $element) { + $request['body'] = preg_replace_callback("/\[" . $element . "\](.*?)\[\/" . $element . "\]/ism", + function ($match) use ($element) { + return '[base64' . $element . ']' . base64_encode($match[1]) . '[/base64' . $element . ']'; + }, + $request['body'] + ); + } + $request['body'] = Markdown::toBBCode($request['body']); + + foreach ($elements as $element) { + $request['body'] = preg_replace_callback("/\[base64" . $element . "\](.*?)\[\/base64" . $element . "\]/ism", + function ($match) use ($element) { + return '[' . $element . ']' . base64_decode($match[1]) . '[/' . $element . ']'; + }, + $request['body'] + ); + } }