use Friendica\Core\Addon;
use Friendica\Util\Network;
use Friendica\Util\XML;
+use League\HTMLToMarkdown\HtmlConverter;
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
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;
+ }
}