*/ class Markdown extends BaseObject { /** * Converts a Markdown string into HTML. The hardwrap parameter maximizes * compatibility with Diaspora in spite of the Markdown standard. * * @brief Converts a Markdown string into HTML * @param string $text * @param bool $hardwrap * @return string * @throws \Exception */ public static function convert($text, $hardwrap = true) { $stamp1 = microtime(true); $MarkdownParser = new MarkdownExtra(); $MarkdownParser->hard_wrap = $hardwrap; $MarkdownParser->code_class_prefix = 'language-'; $html = $MarkdownParser->transform($text); $html = preg_replace('/', '

', '

'], ['
', '
', '
'], $s); // Escaping hashtags that could be titles $s = preg_replace('/^\#([^\s\#])/im', '\#$1', $s); $s = self::convert($s); $regexp = "/([@!])\{(?:([^\}]+?); ?)?([^\} ]+)\}/"; $s = preg_replace_callback($regexp, ['self', 'diasporaMention2BBCodeCallback'], $s); $s = HTML::toBBCode($s); // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands $s = str_replace('♲', html_entity_decode('♲', ENT_QUOTES, 'UTF-8'), $s); // Convert everything that looks like a link to a link $s = preg_replace('/([^\]=]|^)(https?\:\/\/)([a-zA-Z0-9:\/\-?&;.=_~#%$!+,@]+(?