]> git.mxchange.org Git - friendica.git/commitdiff
Issue #6799 - remove linefeeds inside of a table structure
authorMichael <heluecht@pirati.ca>
Sun, 2 Jun 2019 04:18:38 +0000 (04:18 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 2 Jun 2019 04:18:38 +0000 (04:18 +0000)
src/Content/Text/BBCode.php

index e417b38a467b8cbb8ed096a8f9d153e3cb5ce10a..6805369d083d4bc7a8c6d53e4288228ce98a1280 100644 (file)
@@ -1250,6 +1250,25 @@ class BBCode extends BaseObject
                $text = trim($text);
                $text = str_replace("\r\n", "\n", $text);
 
+               // Remove linefeeds inside of the table elements. See issue #6799
+               $search = ["\n[th]", "[th]\n", " [th]", "\n[/th]", "[/th]\n", "[/th] ",
+                       "\n[td]", "[td]\n", " [td]", "\n[/td]", "[/td]\n", "[/td] ",
+                       "\n[tr]", "[tr]\n", " [tr]", "[tr] ", "\n[/tr]", "[/tr]\n", " [/tr]", "[/tr] ",
+                       "[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] "];
+               $replace = ["[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]",
+                       "[td]", "[td]", "[td]", "[/td]", "[/td]", "[/td]",
+                       "[tr]", "[tr]", "[tr]", "[tr]", "[/tr]", "[/tr]", "[/tr]", "[/tr]",
+                       "[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]"];
+               do {
+                       $oldtext = $text;
+                       $text = str_replace($search, $replace, $text);
+               } while ($oldtext != $text);
+
+               // Replace these here only once
+               $search = ["\n[table]", "[/table]\n"];
+               $replace = ["[table]", "[/table]"];
+               $text = str_replace($search, $replace, $text);
+
                // removing multiplicated newlines
                if (Config::get("system", "remove_multiplicated_lines")) {
                        $search = ["\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",