From 3968e77f9e15c149d8cafa1dac37411777bd58bd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Jun 2012 19:49:05 +0200 Subject: New function to convert bbcode to markdown. --- include/bb2diaspora.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'include/bb2diaspora.php') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index d86ba4543..0617ecc5f 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,10 +1,11 @@ ", ">", $Text); // If we find any event code, turn it into an event. - // After we're finished processing the bbcode we'll + // After we're finished processing the bbcode we'll // replace all of the event code with a reformatted version. - if($preserve_nl) $Text = str_replace(array("\n","\r"), array('',''),$Text); + // Convert it to HTML + $Text = bbcode($Text); + + // Now convert HTML to Markdown + $md = new Markdownify(false, false, false); + $Text = $md->parseString($Text); + + // Remove all unconverted tags + $Text = strip_tags($Text); + +/* // Set up the parameters for a URL search string $URLSearchString = "^\[\]"; // Set up the parameters for a MAIL search string @@ -98,7 +109,7 @@ function bb2diaspora($Text,$preserve_nl = false) { // new javascript markdown processor to handle links with images as the link "text" // It is not optimal and may be removed if this ability is restored in the future - $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism", + $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism", '![' . t('image/photo') . '](' . '$2' . ')' . "\n" . '[' . t('link') . '](' . '$1' . ')', $Text); $Text = preg_replace("/\[bookmark\]([$URLSearchString]*)\[\/bookmark\]/ism", '[$1]($1)', $Text); @@ -115,7 +126,7 @@ function bb2diaspora($Text,$preserve_nl = false) { // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '[$2](mailto:$1)', $Text); - + $Text = str_replace('*', '\\*', $Text); $Text = str_replace('_', '\\_', $Text); @@ -158,7 +169,7 @@ function bb2diaspora($Text,$preserve_nl = false) { // $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/s", '$1
' ,$Text); // $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/s", '$1
' ,$Text); - + // $Text = str_replace("[*]", "
  • ", $Text); // Check for font change text @@ -174,10 +185,10 @@ function bb2diaspora($Text,$preserve_nl = false) { // Declare the format for [quote] layout - // $QuoteLayout = '
    $1
    '; + // $QuoteLayout = '
    $1
    '; // Check for [quote] text $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is",">$1\n\n", $Text); - + // Images // html5 video and audio @@ -187,7 +198,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); // $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/", '', $Text); - + // [img=widthxheight]image source[/img] // $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/", '', $Text); @@ -211,7 +222,7 @@ function bb2diaspora($Text,$preserve_nl = false) { if(x($ev,'desc') && x($ev,'start')) { $sub = format_event_diaspora($ev); - + $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/is",$sub,$Text); $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/is",'',$Text); $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/is",'',$Text); @@ -222,7 +233,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text); $Text = preg_replace_callback('/\[(.*?)\]\((.*?)\)/ism','unescape_underscores_in_links',$Text); - +*/ call_hooks('bb2diaspora',$Text); return $Text; -- cgit v1.2.3