mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 23:35:12 +00:00
another attempt at resolving markdown quirks
This commit is contained in:
parent
2d9be60b0a
commit
67ed8641a8
1 changed files with 22 additions and 8 deletions
|
@ -1139,7 +1139,6 @@ function bbcode($Text, $options = []) {
|
|||
btlogger('Text is array: ' . print_r($Text,true));
|
||||
}
|
||||
|
||||
$preserve_nl = ((array_key_exists('preserve_nl',$options)) ? $options['preserve_nl'] : false);
|
||||
$cache = ((array_key_exists('cache',$options)) ? $options['cache'] : false);
|
||||
$newwin = ((array_key_exists('newwin',$options)) ? $options['newwin'] : true);
|
||||
$export = ((array_key_exists('export',$options)) ? $options['export'] : false);
|
||||
|
@ -1250,18 +1249,33 @@ function bbcode($Text, $options = []) {
|
|||
// Convert new line chars to html <br> tags
|
||||
|
||||
$Text = str_replace("\r\n", "\n", $Text);
|
||||
|
||||
// $Text = MarkdownExtra::DefaultTransform($Text);
|
||||
// $Text = str_replace(">\n", '><br>', $Text);
|
||||
|
||||
$Text = str_replace(array("\r", "\n"), array('<br>', '<br>'), $Text);
|
||||
|
||||
// if ($preserve_nl)
|
||||
// $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
|
||||
// BEGIN markdown quirks
|
||||
|
||||
$Text = str_replace('<br>','&_lt;br&_gt;', $Text);
|
||||
|
||||
$Text = MarkdownExtra::DefaultTransform($Text);
|
||||
|
||||
// linefeeds inside code blocks which were converted to <br> will have been converted to <br> by the default transform.
|
||||
// convert them back to <br>. Those which were integral to the original code block before substitution have been escaped further
|
||||
// and will be recovered after we perform this step.
|
||||
|
||||
do {
|
||||
$replaced = $Text;
|
||||
$Text = preg_replace('/\<code\>(.*?)\<\;br\>\;(.*?)\<\/code\>/ism','<code>$1<br>$2</code>',$Text);
|
||||
} while ($replaced != $Text);
|
||||
|
||||
// bbcode code blocks are wrapped in <pre>. Do the same for markdown code blocks so that the styling is consistent
|
||||
|
||||
$Text = str_replace([ '<code>', '</code>' ], [ '<pre><code>', '</code></pre>' ] , $Text);
|
||||
|
||||
$Text = str_replace('&_lt;br&_gt;','<br>', $Text);
|
||||
|
||||
// END markdown quirks
|
||||
|
||||
$Text = str_replace(array("\t", " "), array(" ", " "), $Text);
|
||||
|
||||
|
||||
// Check for [code] text
|
||||
if (strpos($Text,'[code]') !== false) {
|
||||
$Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", 'bb_code', $Text);
|
||||
|
|
Loading…
Reference in a new issue