forked from friendica/friendica-addons
Merge pull request #925 from annando/markdown-escape
Markdown: Escape some elements prior to sending them through Markdown
This commit is contained in:
commit
d18af9c2c4
1 changed files with 20 additions and 0 deletions
|
@ -49,5 +49,25 @@ function markdown_post_local_start(App $a, &$request) {
|
||||||
return;
|
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']);
|
$request['body'] = Markdown::toBBCode($request['body']);
|
||||||
|
|
||||||
|
foreach (array_reverse($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']
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue