]> git.mxchange.org Git - friendica.git/blobdiff - include/bb2diaspora.php
New routines for markdown to html and html to markdown.
[friendica.git] / include / bb2diaspora.php
index 7107c4913950f130e3638c7cb59a40293b386af3..272b69dff9de9b8c5cf60c4abc743d7f8d88a29d 100644 (file)
@@ -5,7 +5,8 @@ require_once("include/event.php");
 require_once("library/markdown.php");
 require_once("include/html2bbcode.php");
 require_once("include/bbcode.php");
-require_once("include/markdownify/markdownify.php");
+require_once("library/html-to-markdown/HTML_To_Markdown.php");
+//require_once("include/markdownify/markdownify.php");
 
 
 // we don't want to support a bbcode specific markdown interpreter
@@ -21,15 +22,15 @@ function diaspora2bb($s) {
        $s = str_replace("\r","",$s);
 
        // <br/> is invalid. Replace it with the valid expression
-       $s = str_replace(array("<br/>", "</p>", "<p>", '<p dir="ltr">'),array("<br />", "<br />", "<br />", "<br />"),$s);
-
-       $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
+       //$s = str_replace(array("<br/>", "</p>", "<p>", '<p dir="ltr">'),array("<br />", "<br />", "<br />", "<br />"),$s);
 
        // Escaping the hash tags
        $s = preg_replace('/\#([^\s\#])/','&#35;$1',$s);
 
        $s = Markdown($s);
 
+       $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
+
        $s = str_replace('&#35;','#',$s);
 
        $s = html2bbcode($s);
@@ -92,12 +93,15 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
                $Text = bbcode($Text, $preserve_nl, false, 4);
 
                // Libertree doesn't convert a harizontal rule if there isn't a linefeed
-               $Text = str_replace(array("<hr />", "<hr>"), array("<br /><hr />", "<br><hr>"), $Text);
+               //$Text = str_replace(array("<hr />", "<hr>"), array("<br /><hr />", "<br><hr>"), $Text);
        }
 
        // Now convert HTML to Markdown
-       $md = new Markdownify(false, false, false);
-       $Text = $md->parseString($Text);
+       $Text = new HTML_To_Markdown($Text);
+
+/*
+       //$md = new Markdownify(false, false, false);
+       //$Text = $md->parseString($Text);
 
        // The Markdownify converter converts underscores '_' in URLs to '\_', which
        // messes up the URL. Manually fix these
@@ -123,6 +127,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
 
        // Remove all unconverted tags
        $Text = strip_tags($Text);
+*/
 
        // Remove any leading or trailing whitespace, as this will mess up
        // the Diaspora signature verification and cause the item to disappear