aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-11-16 20:49:58 +0100
committerMario Vavti <mario@mariovavti.com>2016-11-16 20:49:58 +0100
commit1ad8f20bcea6395cd8f9a50907a36bae1e425352 (patch)
tree82da5b03ccb28d6a697082c8a05cb62e277a3420 /include
parentde421d02efbdd9815719ae13845d5f1e4709ced4 (diff)
downloadvolse-hubzilla-1ad8f20bcea6395cd8f9a50907a36bae1e425352.tar.gz
volse-hubzilla-1ad8f20bcea6395cd8f9a50907a36bae1e425352.tar.bz2
volse-hubzilla-1ad8f20bcea6395cd8f9a50907a36bae1e425352.zip
only turn [] and [x] into checkboxes if it is found inside a checklist
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 75e8a0f52..21bc6de77 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -403,6 +403,15 @@ function bb_definitionList_unescapeBraces($match) {
return '<dt>' . str_replace('\]', ']', $match[1]) . '</dt>';
}
+
+function bb_checklist($match) {
+ $str = $match[1];
+ $str = str_replace("[]", "<li><input type=\"checkbox\" disabled=\"disabled\">", $str);
+ $str = str_replace("[x]", "<li><input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\">", $str);
+ return '<ul class="checklist" style="list-style-type: none;">' . $str . '</ul>';
+}
+
+
/**
* @brief Sanitize style properties from BBCode to HTML.
*
@@ -787,14 +796,11 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("/<br \/>\[\*\]/ism",'[*]',$Text);
$Text = str_replace("[*]", "<li>", $Text);
- $Text = str_replace("[]", "<li><input type=\"checkbox\" disabled=\"disabled\">", $Text);
- $Text = str_replace("[x]", "<li><input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\">", $Text);
// handle nested lists
$endlessloop = 0;
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
- ((strpos($Text, "[/checklist]") !== false) && (strpos($Text, "[checklist]") !== 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)) ||
@@ -806,7 +812,6 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
$Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
$Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
- $Text = preg_replace("/\[checklist\](.*?)\[\/checklist\]/ism", '<ul class="checklist" style="list-style-type: none;">$1</ul>', $Text);
$Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
$Text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]',$Text);
@@ -818,7 +823,13 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
// "[dl" <optional-whitespace> <optional-termStyles> "]" <matchGroup2> "[/dl]"
// where optional-termStyles are: "terms=" <optional-quote> <matchGroup1> <optional-quote>
$Text = preg_replace_callback('/\[dl[[:space:]]*(?:terms=(?:&quot;|")?([a-zA-Z]+)(?:&quot;|")?)?\](.*?)\[\/dl\]/ism', 'bb_definitionList', $Text);
+
+ }
+
+ if (strpos($Text,'[checklist]') !== false) {
+ $Text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $Text);
}
+
if (strpos($Text,'[th]') !== false) {
$Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>', $Text);
}