fix small bug in lists and revert Diaspora list processing to non-Markdownify version
This commit is contained in:
parent
360c35e438
commit
041aeaf4a1
|
@ -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) {
|
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
|
// spaces by "* " to match Diaspora's list format
|
||||||
|
@ -103,10 +109,38 @@ function diaspora_ol($s) {
|
||||||
else
|
else
|
||||||
return $s[0];
|
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) {
|
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>"
|
// bbcode() will convert "[*]" into "<li>" with no closing "</li>"
|
||||||
// Markdownify() is unable to handle these, as it makes each new
|
// Markdownify() is unable to handle these, as it makes each new
|
||||||
// "<li>" into a deeper nested element until it crashes. So pre-format
|
// "<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
|
// 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
|
// to define the closing tag for the list elements. So nested lists
|
||||||
// are going to be flattened out in Diaspora for now
|
// are going to be flattened out in Diaspora for now
|
||||||
|
|
||||||
$endlessloop = 0;
|
$endlessloop = 0;
|
||||||
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
|
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
|
||||||
((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== 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);
|
$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
|
// Convert it to HTML - don't try oembed
|
||||||
// $Text = bbcode($Text, $preserve_nl, false);
|
// $Text = bbcode($Text, $preserve_nl, false);
|
||||||
|
@ -244,15 +270,21 @@ function bb2diaspora($Text,$preserve_nl = false) {
|
||||||
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text);
|
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text);
|
||||||
|
|
||||||
// Check for list text
|
// Check for list 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\](.*?)\[\/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=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=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("/\[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_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
|
||||||
// $Text = preg_replace("/\[li\](.*?)\[\/li\]/s", '<li>$1</li>' ,$Text);
|
$Text = preg_replace("/\[li\]( *)(.*?)\[\/li\]/s", '* $2' ,$Text);
|
||||||
|
}
|
||||||
|
|
||||||
// Just get rid of table tags since Diaspora doesn't support tables
|
// Just get rid of table tags since Diaspora doesn't support tables
|
||||||
$Text = preg_replace("/\[th\](.*?)\[\/th\]/s", '$1' ,$Text);
|
$Text = preg_replace("/\[th\](.*?)\[\/th\]/s", '$1' ,$Text);
|
||||||
|
|
|
@ -166,14 +166,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
|
||||||
|
|
||||||
// Check for list text
|
// Check for list text
|
||||||
$Text = str_replace("[*]", "<li>", $Text);
|
$Text = str_replace("[*]", "<li>", $Text);
|
||||||
$Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text);
|
|
||||||
|
|
||||||
// handle nested lists
|
// handle nested lists
|
||||||
$endlessloop = 0;
|
$endlessloop = 0;
|
||||||
|
|
||||||
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
|
while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
|
||||||
((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== 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="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=\](.*?)\[\/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);
|
$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("/\[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("/\[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("/\[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);
|
$Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text);
|
||||||
|
|
Loading…
Reference in a new issue