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
|
||||
|
|
|
@ -168,6 +168,8 @@ function bb_remove_share_information($Text, $plaintext = false, $nolink = false)
|
|||
}
|
||||
|
||||
function bb_cleanup_share($shared, $plaintext, $nolink) {
|
||||
$shared[1] = trim($shared[1]);
|
||||
|
||||
if (!in_array($shared[2], array("type-link", "type-video")))
|
||||
return($shared[0]);
|
||||
|
||||
|
@ -178,7 +180,7 @@ function bb_cleanup_share($shared, $plaintext, $nolink) {
|
|||
return($shared[0]);
|
||||
|
||||
if ($nolink)
|
||||
return(trim($shared[1]));
|
||||
return($shared[1]);
|
||||
|
||||
$title = "";
|
||||
$link = "";
|
||||
|
@ -189,6 +191,9 @@ function bb_cleanup_share($shared, $plaintext, $nolink) {
|
|||
if (isset($bookmark[1][0]))
|
||||
$link = $bookmark[1][0];
|
||||
|
||||
if (($title != "") AND (strpos($title, $shared[1]) !== false))
|
||||
$shared[1] = $title;
|
||||
|
||||
if (($title != "") AND ((strpos($shared[1],$title) !== false) OR
|
||||
(similar_text($shared[1],$title) / strlen($title)) > 0.9))
|
||||
$title = "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue