diff --git a/doc/bbcode.html b/doc/bbcode.html
index 3e9bda1d9..5a51135ea 100644
--- a/doc/bbcode.html
+++ b/doc/bbcode.html
@@ -27,12 +27,31 @@
[list=a]
[list=A]
[ul]
-[ol]
+[ol]
+[dl]
+[dl terms="biumlh"] — where style of the terms can be any combination of:
+
+ - b
- bold
+ - i
- italic
+ - u
- underline
+ - m
- monospace
+ - l
- large
+ - h
- horizontal — like this defintion list
+
+
For example:
[ul]
[*] First list element
[*] Second list element
[/ul]
Will render something like:
- First list element
- - Second list element
+ Second list element
+
+or
[dl terms="b"]
[*= First element term] First element description
[*= Second element term] Second element description
[/dl]
Will render something like:
+
+- First element term
- First element description
+- Second element term
- Second element description
+
+
+
There's also:
- [hr]
diff --git a/include/bbcode.php b/include/bbcode.php
index b8cd23f59..1640307f8 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -345,6 +345,46 @@ function bb_spoilertag($match) {
return '' . $openclose . '
' . $text . '
';
}
+function bb_definitionList($match) {
+ // $match[1] is the markup styles for the "terms" in the definition list.
+ // $match[2] is the content between the [dl]...[/dl] tags
+
+ $classes = '';
+ if (stripos($match[1], "b") !== false) $classes .= 'dl-terms-bold ';
+ if (stripos($match[1], "i") !== false) $classes .= 'dl-terms-italic ';
+ if (stripos($match[1], "u") !== false) $classes .= 'dl-terms-underline ';
+ if (stripos($match[1], "l") !== false) $classes .= 'dl-terms-large ';
+ if (stripos($match[1], "m") !== false) $classes .= 'dl-terms-monospace ';
+ if (stripos($match[1], "h") !== false) $classes .= 'dl-horizontal '; // dl-horizontal is already provided by bootstrap
+ if (strlen($classes) === 0) $classes = "dl-terms-plain";
+
+ // The bbcode transformation will be:
+ // [*=term-text] description-text => - term-text
- description-text
+ // then after all replacements have been made, the
remaining the start of the
+ // string can be removed. HTML5 allows the missing end tag.
+ // Using '(?\n";
+ $listElements = preg_replace(
+ '/\[\*=([[:print:]]*?)(?$1- ',
+ $match[2]
+ );
+ // Unescape any \] inside the
- tags
+ $listElements = preg_replace_callback('/
- (.*?)<\/dt>/ism', 'bb_definitionList_unescapeBraces', $listElements);
+
+ // Remove the extra at the start of the string, if there is one.
+ $firstOpenTag = strpos($listElements, '
- ');
+ $firstCloseTag = strpos($listElements, $closeDescriptionTag);
+ if ($firstCloseTag !== false && ($firstOpenTag === false || ($firstCloseTag < $firstOpenTag))) {
+ $listElements = preg_replace( '/<\/dd>/ism', '', $listElements, 1);
+ }
+
+ return '
' . $listElements . '
';;
+}
+function bb_definitionList_unescapeBraces($match) {
+ return ' - ' . str_replace('\]', ']', $match[1]) . '
';
+}
+
/**
* @brief Sanitize style properties from BBCode to HTML.
*
@@ -713,6 +753,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) ||
((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) ||
+ ((strpos($Text, "[/dl]") !== false) && (strpos($Text, "[dl") !== 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);
@@ -724,6 +765,13 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '', $Text);
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '', $Text);
$Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", ' - $1
', $Text);
+
+ // [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
+ // etc. style may be specified for the "terms" in the definition list. The quotation marks
+ // are also optional. The regex looks intimidating, but breaks down as:
+ // "[dl" "]" "[/dl]"
+ // where optional-termStyles are: "terms="
+ $Text = preg_replace_callback('/\[dl[[:space:]]*(?:terms=(?:"|")?([a-zA-Z]+)(?:"|")?)?\](.*?)\[\/dl\]/ism', 'bb_definitionList', $Text);
}
if (strpos($Text,'[th]') !== false) {
$Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1 | ', $Text);
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js
index 21ce2d150..ca51230df 100644
--- a/view/js/autocomplete.js
+++ b/view/js/autocomplete.js
@@ -265,7 +265,7 @@ function string2bb(element) {
$.fn.bbco_autocomplete = function(type) {
if(type=='bbcode') {
- var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'open', 'spoiler', 'map', 'nobb', 'list', 'ul', 'ol', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer'];
+ var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'open', 'spoiler', 'map', 'nobb', 'list', 'ul', 'ol', 'dl', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer'];
var open_elements = ['observer.baseurl', 'observer.address', 'observer.photo', 'observer.name', 'observer.webname', 'observer.url', '*', 'hr', ];
var elements = open_close_elements.concat(open_elements);
diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css
index 290a1a697..e1076a79f 100644
--- a/view/theme/redbasic/css/style.css
+++ b/view/theme/redbasic/css/style.css
@@ -1827,6 +1827,27 @@ nav .badge.mail-update:hover {
margin-top:-3px;
}
+dl.bb-dl > dt {
+ /* overriding the default dl style from bootstrap, as bootstrap's
+ style of a bold unindented line followed by a plain unindented
+ line is already acheivable in bbcode without dl */
+ font-weight: normal;
+}
+dl.dl-terms-monospace > dt { font-family: monospace; }
+dl.dl-terms-bold > dt { font-weight: bold; }
+dl.dl-terms-italic > dt { font-style: italic; }
+dl.dl-terms-underline > dt { text-decoration: underline; }
+dl.dl-terms-large > dt { font-size: 120%; }
+dl.bb-dl:not(.dl-horizontal) > dd {
+ display: block;
+ margin-left: 2em;
+}
+dl.bb-dl > dd > li {
+ /* adding some indent so bullet-list items will line up better with
+ dl descriptions if someone wants to be impure and combine them */
+ margin-left: 1em;
+}
+
.bootstrap-tagsinput .tag:before {
/* Copied from icon-asterisk, is there a better way to do it? */
font-family: FontAwesome;