aboutsummaryrefslogtreecommitdiffstats
path: root/include/bb2diaspora.php
diff options
context:
space:
mode:
authorfermionic <fermion@gmx.com>2012-06-23 19:08:32 -0700
committerfermionic <fermion@gmx.com>2012-06-23 19:08:32 -0700
commit098c74a12a7b370ccd9ca6d10987feac4b0d61d3 (patch)
tree01cd1478ac4e00f08e76b154d849a708fb914550 /include/bb2diaspora.php
parent381d0912672cda6575368d242565310a93e202d4 (diff)
parent1f968396749f8cac31aaeee770ae7fc5aff48f38 (diff)
downloadvolse-hubzilla-098c74a12a7b370ccd9ca6d10987feac4b0d61d3.tar.gz
volse-hubzilla-098c74a12a7b370ccd9ca6d10987feac4b0d61d3.tar.bz2
volse-hubzilla-098c74a12a7b370ccd9ca6d10987feac4b0d61d3.zip
Merge pull request #354 from fermionic/always-terminate-bbcode-list-elements
Fix Diaspora list formatting
Diffstat (limited to 'include/bb2diaspora.php')
-rw-r--r--include/bb2diaspora.php44
1 files changed, 41 insertions, 3 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index 96cc735bd..75ba57dff 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -68,9 +68,14 @@ function stripdcode_br_cb($s) {
function diaspora_ul($s) {
- // Replace "[\\*]" followed by any number (including zero) of
+ // Replace "[*]" followed by any number (including zero) of
// spaces by "* " to match Diaspora's list format
- return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]);
+ if( strpos($s[0], "[list]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ul]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
@@ -80,12 +85,45 @@ function diaspora_ol($s) {
// 1. First element
// 1. Second element
// 1. Third element
- return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]);
+ if( strpos($s[0], "[list=1]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=i]") === 0 )
+ return '<ul class="listlowerroman" style="list-style-type: lower-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=I]") === 0 )
+ return '<ul class="listupperroman" style="list-style-type: upper-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=a]") === 0 )
+ return '<ul class="listloweralpha" style="list-style-type: lower-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=A]") === 0 )
+ return '<ul class="listupperalpha" style="list-style-type: upper-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ol]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
function bb2diaspora($Text,$preserve_nl = false) {
+ // bbcode() will convert "[*]" into "<li>" with no closing "</li>"
+ // Markdownify() is unable to handle these, as it makes each new
+ // "<li>" into a deeper nested element until it crashes. So pre-format
+ // the lists as Diaspora lists before sending the $Text to bbcode()
+ //
+ // Note that regular expressions are really not suitable for parsing
+ // text with opening and closing tags, so nested lists may make things
+ // wonky
+ $endlessloop = 0;
+ while ((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false) && (++$endlessloop < 20)) {
+ $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ }
+ $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
+
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, $preserve_nl, false);