Merge pull request #360 from fermionic/more-nested-lists
allow nested [ol] and [ul] lists too
This commit is contained in:
commit
cb450d3365
2 changed files with 13 additions and 10 deletions
|
@ -109,20 +109,22 @@ function bb2diaspora($Text,$preserve_nl = false) {
|
|||
// "<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
|
||||
// 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) && (++$endlessloop < 20)) {
|
||||
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)) {
|
||||
$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);
|
||||
|
|
|
@ -162,7 +162,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
|
|||
|
||||
// handle nested lists
|
||||
$endlessloop = 0;
|
||||
while ((strpos($Text, "[/list]") !== false) and (strpos($Text, "[list") !== false) and (++$endlessloop < 20)) {
|
||||
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)) {
|
||||
$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);
|
||||
|
@ -170,10 +172,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
|
|||
$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("/\[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("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text);
|
||||
$Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>' ,$Text);
|
||||
|
|
Loading…
Reference in a new issue