aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorZach Prezkuta <fermion@gmx.com>2012-07-05 12:52:20 -0600
committerZach Prezkuta <fermion@gmx.com>2012-07-05 12:54:52 -0600
commit041aeaf4a159e277b828d8a386c0968657afb723 (patch)
treebf8f756bb5fd6711dea56c18f5ea6662f1e25cbf /include
parent360c35e438f4ecb6a60cefde8ab8b0e3f6f0c57f (diff)
downloadvolse-hubzilla-041aeaf4a159e277b828d8a386c0968657afb723.tar.gz
volse-hubzilla-041aeaf4a159e277b828d8a386c0968657afb723.tar.bz2
volse-hubzilla-041aeaf4a159e277b828d8a386c0968657afb723.zip
fix small bug in lists and revert Diaspora list processing to non-Markdownify version
Diffstat (limited to 'include')
-rw-r--r--include/bb2diaspora.php70
-rw-r--r--include/bbcode.php5
2 files changed, 54 insertions, 21 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index c93b60d0d..75dadb84c 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -70,6 +70,12 @@ function stripdcode_br_cb($s) {
}
+//////////////////////
+// The following "diaspora_ul" and "diaspora_ol" are only appropriate for the
+// pre-Markdownify conversion. If Markdownify isn't used, use the non-Markdownify
+// versions below
+//////////////////////
+/*
function diaspora_ul($s) {
// Replace "[*]" followed by any number (including zero) of
// spaces by "* " to match Diaspora's list format
@@ -103,10 +109,38 @@ function diaspora_ol($s) {
else
return $s[0];
}
+*/
+
+//////////////////////
+// Non-Markdownify versions of "diaspora_ol" and "diaspora_ul"
+//////////////////////
+function diaspora_ul($s) {
+ // Replace "[\\*]" followed by any number (including zero) of
+ // spaces by "* " to match Diaspora's list format
+ return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]);
+}
+
+function diaspora_ol($s) {
+ // A hack: Diaspora will create a properly-numbered ordered list even
+ // if you use '1.' for each element of the list, like:
+ // 1. First element
+ // 1. Second element
+ // 1. Third element
+ return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]);
+}
function bb2diaspora($Text,$preserve_nl = false) {
+//////////////////////
+// An attempt was made to convert bbcode to html and then to markdown
+// consisting of the following lines.
+// I'm undoing this as we have a lot of bbcode constructs which
+// were simply getting lost, for instance bookmark, vimeo, video, youtube, events, etc.
+// We can try this again, but need a very good test sequence to verify
+// all the major bbcode constructs that we use are getting through.
+//////////////////////
+/*
// 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
@@ -115,6 +149,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// Note that to get nested lists to work for Diaspora, we would need
// to define the closing tag for the list elements. So nested lists
// are going to be flattened out in Diaspora for now
+
$endlessloop = 0;
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) ||
@@ -129,16 +164,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
}
-
-
-//////////////////////
-// An attempt was made to convert bbcode to html and then to markdown
-// consisting of the following lines.
-// I'm undoing this as we have a lot of bbcode constructs which
-// were simply getting lost, for instance bookmark, vimeo, video, youtube, events, etc.
-// We can try this again, but need a very good test sequence to verify
-// all the major bbcode constructs that we use are getting through.
-//////////////////////
+*/
// Convert it to HTML - don't try oembed
// $Text = bbcode($Text, $preserve_nl, false);
@@ -244,15 +270,21 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text);
// Check for list text
- $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
- $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/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("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
-// $Text = preg_replace("/\[li\](.*?)\[\/li\]/s", '<li>$1</li>' ,$Text);
+ $endlessloop = 0;
+ 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, "[/li]") !== false) && (strpos($Text, "[li]") !== 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);
+ $Text = preg_replace("/\[li\]( *)(.*?)\[\/li\]/s", '* $2' ,$Text);
+ }
// Just get rid of table tags since Diaspora doesn't support tables
$Text = preg_replace("/\[th\](.*?)\[\/th\]/s", '$1' ,$Text);
diff --git a/include/bbcode.php b/include/bbcode.php
index cb4a0bc6f..55a879497 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -166,14 +166,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// Check for list text
$Text = str_replace("[*]", "<li>", $Text);
- $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text);
// handle nested lists
$endlessloop = 0;
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))) && (++$endlessloop < 20)) {
+ ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) ||
+ ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) {
$Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
@@ -183,6 +183,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</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\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text);
}
$Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text);