Markdown: Escape some elements prior to sending them through Markdown

pull/925/head
Michael 2019-12-27 01:35:15 +00:00
parent 4954cabd9d
commit 2f3e727570
1 changed files with 20 additions and 0 deletions

View File

@ -49,5 +49,25 @@ function markdown_post_local_start(App $a, &$request) {
return; return;
} }
$request['body'] = Markdown::toBBCode($request['body']); // 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']
);
}
} }