]> git.mxchange.org Git - friendica.git/commitdiff
Rework new lines around list BBCode
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 19 Mar 2023 03:23:50 +0000 (23:23 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 19 Mar 2023 03:35:51 +0000 (23:35 -0400)
- Remove blanket new lines remover in HTML::toBBCode
- Add test to ensure the commutativity of the markups

src/Content/Text/HTML.php
tests/src/Content/Text/BBCodeTest.php
tests/src/Content/Text/HTMLTest.php

index ebd74121b11552414cca0473c9fd305867326614..c1bcb0b5b00e4adf924853112fa18fe9f5e74a22 100644 (file)
@@ -281,9 +281,9 @@ class HTML
                        self::tagToBBCode($doc, 'div', [], "\r", "\r");
                        self::tagToBBCode($doc, 'p', [], "\n", "\n");
 
-                       self::tagToBBCode($doc, 'ul', [], "[ul]", "[/ul]");
-                       self::tagToBBCode($doc, 'ol', [], "[ol]", "[/ol]");
-                       self::tagToBBCode($doc, 'li', [], "[*]", "");
+                       self::tagToBBCode($doc, 'ul', [], "[ul]", "\n[/ul]");
+                       self::tagToBBCode($doc, 'ol', [], "[ol]", "\n[/ol]");
+                       self::tagToBBCode($doc, 'li', [], "\n[*]", "");
 
                        self::tagToBBCode($doc, 'hr', [], "[hr]", "");
 
@@ -349,33 +349,6 @@ class HTML
                                $message = str_replace("\n\n\n", "\n\n", $message);
                        } while ($oldmessage != $message);
 
-                       do {
-                               $oldmessage = $message;
-                               $message = str_replace(
-                                       [
-                                               "[/size]\n\n",
-                                               "\n[hr]",
-                                               "[hr]\n",
-                                               "\n[list",
-                                               "[/list]\n",
-                                               "\n[/",
-                                               "[list]\n",
-                                               "[list=1]\n",
-                                               "\n[*]"],
-                                       [
-                                               "[/size]\n",
-                                               "[hr]",
-                                               "[hr]",
-                                               "[list",
-                                               "[/list]",
-                                               "[/",
-                                               "[list]",
-                                               "[list=1]",
-                                               "[*]"],
-                                       $message
-                               );
-                       } while ($message != $oldmessage);
-
                        $message = str_replace(
                                ['[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'],
                                ['[b]', '[/b]', '[i]', '[/i]'],
index 698b37e70001ee4b5fa50b3c8007c06f4e2d9a49..b7328d67d76c1e8e3938ce6cf1186ab7f629e689 100644 (file)
@@ -265,7 +265,15 @@ Karl Marx - Die ursprüngliche Akkumulation
                        'task-12900-header-with-paragraphs' => [
                                'expectedHTML' => '<h1>Header</h1><p>Some Chapter</p>',
                                'text' => '[h1]Header[/h1]Some Chapter',
-                       ]
+                       ],
+                       'bug-12842-ul-newlines' => [
+                               'expectedHTML' => '<p>This is:</p><ul><li>some<br></li><li>amazing<br></li><li>list</li></ul>',
+                               'text' => "This is:\r\n[ul]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ul]",
+                       ],
+                       'bug-12842-ol-newlines' => [
+                               'expectedHTML' => '<p>This is:</p><ol><li>some<br></li><li>amazing<br></li><li>list</li></ol>',
+                               'text' => "This is:\r\n[ol]\r\n[*]some\r\n[*]amazing\r\n[*]list\r\n[/ol]",
+                       ],
                ];
        }
 
index 259d0e6f0227eeb59f07c3df6886efdc4df3c5ed..dc55ad0f0b2c258fc2f970a1b28aa4a8578e8e59 100644 (file)
@@ -88,6 +88,24 @@ its surprisingly good",
                                'expectedBBCode' => '[url=https://dev-friendica.mrpetovan.com/profile/hypolite]@hypolite[/url] 0',
                                'html' => '<p><span class="h-card"><a href="https://dev-friendica.mrpetovan.com/profile/hypolite" class="u-url mention">@<span>hypolite</span></a></span> 0</p>',
                        ],
+                       'bug-12842-ul-new-lines' => [
+                               'expectedBBCode' => 'This is:
+[ul]
+[*]some
+[*]amazing
+[*]list
+[/ul]',
+                               'html'=> '<p>This is:</p><ul><li>some</li><li>amazing</li><li>list</li></ul>',
+                       ],
+                       'bug-12842-ol-new-lines' => [
+                               'expectedBBCode' => 'This is:
+[ol]
+[*]some
+[*]amazing
+[*]list
+[/ol]',
+                               'html'=> '<p>This is:</p><ol><li>some</li><li>amazing</li><li>list</li></ol>',
+                       ],
                ];
        }