X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FText%2FHTML.php;h=c256717a159c972fff3bdac91af123fe6486dcce;hb=5456ef01855f7f6bda4f137980df5a1793712bb1;hp=d6e699ed7b90e0b894419a823c911cdd08de8bcf;hpb=2fa6cc000013089d59d9cc221b544ed1a7a4cd37;p=friendica.git diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index d6e699ed7b..c256717a15 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -11,6 +11,7 @@ use DOMXPath; use Friendica\Core\Addon; use Friendica\Util\Network; use Friendica\Util\XML; +use League\HTMLToMarkdown\HtmlConverter; class HTML { @@ -122,7 +123,7 @@ class HTML // Removing code blocks before the whitespace removal processing below $codeblocks = []; $message = preg_replace_callback( - '#
(.*)
#iUs',
+ '#(.*)
#iUs',
function ($matches) use (&$codeblocks) {
$return = '[codeblock-' . count($codeblocks) . ']';
@@ -131,7 +132,7 @@ class HTML
$prefix = '[code=' . $matches[1] . ']';
}
- $codeblocks[] = $prefix . trim($matches[2]) . '[/code]';
+ $codeblocks[] = $prefix . PHP_EOL . trim($matches[2]) . PHP_EOL . '[/code]';
return $return;
},
$message
@@ -520,7 +521,7 @@ class HTML
// A list of some links that should be ignored
$list = ["/user/", "/tag/", "/group/", "/profile/", "/search?search=", "/search?tag=", "mailto:", "/u/", "/node/",
- "//facebook.com/profile.php?id=", "//plus.google.com/", "//twitter.com/"];
+ "//plus.google.com/", "//twitter.com/"];
foreach ($list as $listitem) {
if (strpos($treffer[1], $listitem) !== false) {
$ignore = true;
@@ -672,4 +673,19 @@ class HTML
return trim($message);
}
+
+ /**
+ * Converts provided HTML code to Markdown. The hardwrap parameter maximizes
+ * compatibility with Diaspora in spite of the Markdown standards.
+ *
+ * @param string $html
+ * @return string
+ */
+ public static function toMarkdown($html)
+ {
+ $converter = new HtmlConverter(['hard_break' => true]);
+ $markdown = $converter->convert($html);
+
+ return $markdown;
+ }
}