diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 33f91b43d..2e133372d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -36,14 +36,10 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Event; -use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; -use Friendica\Object\Image; -use Friendica\Protocol\Activity; -use Friendica\Util\Images; use Friendica\Util\Map; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy; @@ -1402,12 +1398,12 @@ class BBCode } // Check for headers - $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); - $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); - $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); - $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); - $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '
$1
', $text); - $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '
$1
', $text); + $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); + $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); + $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); + $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); + $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '

$1

', $text); + $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '

$1

', $text); // Check for paragraph $text = preg_replace("(\[p\](.*?)\[\/p\])ism", '

$1

', $text); @@ -1460,6 +1456,7 @@ class BBCode // @deprecated since 2021.12, left for backward-compatibility reasons $text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism", '$2', $text); // Add HTML new lines + $text = str_replace("\n\n", '

', $text); $text = str_replace("\n", '
', $text); // handle nested lists @@ -1469,27 +1466,27 @@ class BBCode ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) || ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) || ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) { - $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '

', $text); - $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '', $text); - $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '', $text); + $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '

', $text); + $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '

', $text); $text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '

  • $1
  • ', $text); } $text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1', $text); $text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1', $text); $text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1', $text); - $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ', $text); - $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '

    $1

    ', $text); + $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = str_replace('[hr]', '


    ', $text); + $text = str_replace('[hr]', '


    ', $text); if (!$for_plaintext) { $text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) { @@ -1523,7 +1520,7 @@ class BBCode } // Declare the format for [quote] layout - $QuoteLayout = '

    $1
    '; + $QuoteLayout = '

    $1

    '; // Check for [quote] text // handle nested quotes @@ -1938,6 +1935,10 @@ class BBCode : [] ); + if (strpos($text, '

    ') !== false || strpos($text, '

    ') !== false) { + $text = '

    ' . $text . '

    '; + } + $text = HTML::purify($text, $allowedIframeDomains); DI::profiler()->stopRecording(); diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 810b421ca..b4b4039f6 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -141,7 +141,7 @@ class Status extends BaseFactory // Add the title to text / html if set if (!empty($item['title'])) { $text .= $item['title'] . ' '; - $title = sprintf("[h4]%s[/h4]\n", $item['title']); + $title = sprintf("[h4]%s[/h4]", $item['title']); } $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . ($item['raw-body'] ?? $item['body'])), BBCode::TWITTER_API); diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 4c1292344..a7de2388e 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -257,6 +257,14 @@ Karl Marx - Die ursprüngliche Akkumulation 'task-10886-deprecate-class' => [ 'expectedHTML' => ':heart_nb:', 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', + ], + 'task-12900-multiple-paragraphs' => [ + 'expectedHTML' => '

    Header

    This is a paragraph
    with a line feed.

    Second Chapter

    ', + 'text' => "[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter", + ], + 'task-12900-header-with-paragraphs' => [ + 'expectedHTML' => '

    Header

    Some Chapter

    ', + 'text' => '[h1]Header[/h1]Some Chapter', ] ]; } diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 883894589..86b91deb3 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -64,7 +64,7 @@ class StatusTest extends FixtureTest ->toArray(); self::assertStringStartsWith('item_title', $status['text']); - self::assertStringStartsWith('

    item_title


    perspiciatis impedit voluptatem', $status['friendica_html']); + self::assertStringStartsWith('

    item_title

    perspiciatis impedit voluptatem', $status['friendica_html']); } /**