aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-24 17:50:27 +0100
committerMario <mario@mariovavti.com>2024-03-24 17:00:56 +0000
commit7c4362db536414302477e85a3e840ac58bd1e084 (patch)
tree8678f0c6a2fe793526c08a1fb682c543957e12be /include
parentf7bf9ede7235e70605efd6e85469f5b9aa9ee320 (diff)
downloadvolse-hubzilla-7c4362db536414302477e85a3e840ac58bd1e084.tar.gz
volse-hubzilla-7c4362db536414302477e85a3e840ac58bd1e084.tar.bz2
volse-hubzilla-7c4362db536414302477e85a3e840ac58bd1e084.zip
make sure we preserve linefeeds in the actual content of lists and tables also add tests
(cherry picked from commit 3c0d6339bb12bd7fbf65ba7a79078e39737b4387)
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php25
1 files changed, 16 insertions, 9 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 79cb82c0b..db3efe9f8 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1059,8 +1059,8 @@ function bb_fix_lf($match) {
// be converted to '<br />' and turn your neatly crafted tables into a whole lot of
// empty space.
- $new_content = str_replace(["\n\r", "\n", "\r"], '', $match[1]);
- return str_replace($match[1], $new_content, $match[0]);
+ $new_content = preg_replace("/\]\s+\[/",'][', $match[1]);
+ return str_replace($match[1], trim($new_content, "\r\n"), $match[0]);
}
function bbtopoll($s) {
@@ -1553,6 +1553,20 @@ function bbcode($text, $options = []) {
$text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $text);
}
+
+ if (strpos($text,'[/table]') !== false) {
+ $text = str_replace(["[/table]\r", "[/table]\n"], '[/table]', $text);
+
+ $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
+ $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '<table>$1</table>', $text);
+
+ $text = preg_replace_callback("/\[table border=1\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
+ $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '<table class="table table-responsive table-bordered" >$1</table>', $text);
+
+ $text = preg_replace_callback("/\[table border=0\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
+ $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table class="table table-responsive" >$1</table>', $text);
+ }
+
if (strpos($text,'[th]') !== false) {
$text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>', $text);
}
@@ -1565,13 +1579,6 @@ function bbcode($text, $options = []) {
$text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '<tr>$1</tr>', $text);
}
- if (strpos($text,'[/table]') !== false) {
- $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
- $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '<table>$1</table>', $text);
- $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '<table class="table table-responsive table-bordered" >$1</table>', $text);
- $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table class="table table-responsive" >$1</table>', $text);
- }
-
$text = str_replace('[hr]', '<hr />', $text);
// This is actually executed in prepare_body()