aboutsummaryrefslogtreecommitdiffstats
path: root/include/bbcode.php
diff options
context:
space:
mode:
authorTreer <treer.git@the-bordello.com>2016-04-30 02:03:38 +1000
committerTreer <treer.git@the-bordello.com>2016-04-30 02:03:38 +1000
commitb5b21ecad7b164168fbc75792c7285700cee5c9f (patch)
tree7c9b758eed2c726799d2d66ccdca7bd15a1b1c07 /include/bbcode.php
parent9d079e5d2b3dad4e9d0ce962ba2cd8a815a297db (diff)
downloadvolse-hubzilla-b5b21ecad7b164168fbc75792c7285700cee5c9f.tar.gz
volse-hubzilla-b5b21ecad7b164168fbc75792c7285700cee5c9f.tar.bz2
volse-hubzilla-b5b21ecad7b164168fbc75792c7285700cee5c9f.zip
improve whitespace control around definition list ([dl]) bbcode
Diffstat (limited to 'include/bbcode.php')
-rw-r--r--include/bbcode.php10
1 files changed, 6 insertions, 4 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 1640307f8..5bd5301cc 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -360,14 +360,16 @@ function bb_definitionList($match) {
// The bbcode transformation will be:
// [*=term-text] description-text => </dd> <dt>term-text<dt><dd> description-text
- // then after all replacements have been made, the </dd> remaining the start of the
- // string can be removed. HTML5 allows the missing end tag.
+ // then after all replacements have been made, the extra </dd> at the start of the
+ // first line can be removed. HTML5 allows the tag to be missing from the end of the last line.
// Using '(?<!\\\)' to allow backslash-escaped closing braces to appear in the term-text.
$closeDescriptionTag = "</dd>\n";
+ $eatLeadingSpaces = '(?:&nbsp;|[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element
+ $listElements = preg_replace('/^(\n|<br \/>)/', '', $match[2]); // ltrim the first newline
$listElements = preg_replace(
- '/\[\*=([[:print:]]*?)(?<!\\\)\]/ism',
+ '/' . $eatLeadingSpaces . '\[\*=([[:print:]]*?)(?<!\\\)\]/ism',
$closeDescriptionTag . '<dt>$1</dt><dd>',
- $match[2]
+ $listElements
);
// Unescape any \] inside the <dt> tags
$listElements = preg_replace_callback('/<dt>(.*?)<\/dt>/ism', 'bb_definitionList_unescapeBraces', $listElements);