From: Michael Date: Wed, 17 May 2023 08:17:23 +0000 (+0000) Subject: Unify the heading levels X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8b264c38fe73bbbf724cd12e4233fe831248f526;p=friendica.git Unify the heading levels --- diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index c597554455..89bd802027 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1403,12 +1403,32 @@ 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); + + if ($simple_html == self::INTERNAL) { + //Ensure to always start with

if possible + $heading_count = 0; + for ($level = 6; $level > 0; $level--) { + if (preg_match("(\[h$level\].*?\[\/h$level\])ism", $text)) { + $heading_count++; + } + } + if ($heading_count > 0) { + $heading = min($heading_count + 3, 6); + for ($level = 6; $level > 0; $level--) { + if (preg_match("(\[h$level\].*?\[\/h$level\])ism", $text)) { + $text = preg_replace("(\[h$level\](.*?)\[\/h$level\])ism", "

$1

", $text); + $heading--; + } + } + } + } else { + $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);