]> git.mxchange.org Git - friendica.git/commitdiff
Prevents share block new lines from being converted to HTML <br> tags
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 6 Dec 2020 00:55:01 +0000 (19:55 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 6 Dec 2020 00:55:16 +0000 (19:55 -0500)
- Address https://github.com/friendica/friendica/pull/9621#issuecomment-739333767

src/Content/Text/BBCode.php

index 38171d29513d8b103435ed949967772dfb597995..32eb35f76c12ffa1f2cfa80c9e1f639f91652ee4 100644 (file)
@@ -1378,6 +1378,9 @@ class BBCode
                                        } while ($oldtext != $text);
                                }
 
+                               // Add HTML new lines
+                               $text = str_replace("\n", '<br>', $text);
+
                                /// @todo Have a closer look at the different html modes
                                // Handle attached links or videos
                                if ($simple_html == self::ACTIVITYPUB) {
@@ -1848,18 +1851,16 @@ class BBCode
                                return $text;
                        }); // Escaped noparse, nobb, pre
 
-                       // Remove escaping tags
-                       $text = preg_replace("/\[noparse\](.*?)\[\/noparse\]/ism", '\1', $text);
-                       $text = preg_replace("/\[nobb\](.*?)\[\/nobb\]/ism", '\1', $text);
+                       // Remove escaping tags and replace new lines that remain
+                       $text = preg_replace_callback("/\[(noparse|nobb)\](.*?)\[\/\1\]/ism", function ($match) {
+                               return str_replace("\n", "<br>", $match[2]);
+                       }, $text);
 
                        // Additionally, [pre] tags preserve spaces
                        $text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", function ($match) {
-                               return str_replace(' ', '&nbsp;', htmlentities($match[1], ENT_NOQUOTES,'UTF-8'));
+                               return str_replace([' ', "\n"], ['&nbsp;', "<br>"], htmlentities($match[1], ENT_NOQUOTES,'UTF-8'));
                        }, $text);
 
-                       // Add HTML new lines
-                       $text = str_replace("\n", '<br>', $text);
-
                        return $text;
                }); // Escaped code