New routines for markdown to html and html to markdown.
This commit is contained in:
parent
c8a1057300
commit
2f46675a89
9 changed files with 2368 additions and 2936 deletions
|
|
@ -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\#])/','#$1',$s);
|
||||
|
||||
$s = Markdown($s);
|
||||
|
||||
$s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
|
||||
|
||||
$s = str_replace('#','#',$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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue