diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php index dba51d6e06e44268c5ed9a2bc1e983ff70fef54d..884b2d7f31058766a49b86ef5bc79f16a0ddecb2 100644 --- a/app/classes/Framadate/Utils.php +++ b/app/classes/Framadate/Utils.php @@ -134,30 +134,13 @@ class Utils { } public static function markdown($md, $clear) { - preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $md, $md_a_img); // Markdown [](href) - preg_match_all('/!\[(.*?)\]\((.*?)\)/', $md, $md_img); // Markdown  - preg_match_all('/\[(.*?)\]\((.*?)\)/', $md, $md_a); // Markdown [text](href) - if (isset($md_a_img[2][0]) && $md_a_img[2][0] != '' && isset($md_a_img[3][0]) && $md_a_img[3][0] != '') { // [](href) + $parseDown = new \Parsedown(); - $text = self::htmlEscape($md_a_img[1][0]); - $html = '<a href="' . self::htmlEscape($md_a_img[3][0]) . '"><img src="' . self::htmlEscape($md_a_img[2][0]) . '" class="img-responsive" alt="' . $text . '" title="' . $text . '" /></a>'; + $html = $parseDown + ->setMarkupEscaped(true) + ->line($md); - } elseif (isset($md_img[2][0]) && $md_img[2][0] != '') { //  - - $text = self::htmlEscape($md_img[1][0]); - $html = '<img src="' . self::htmlEscape($md_img[2][0]) . '" class="img-responsive" alt="' . $text . '" title="' . $text . '" />'; - - } elseif (isset($md_a[2][0]) && $md_a[2][0] != '') { // [text](href) - - $text = self::htmlEscape($md_a[1][0]); - $html = '<a href="' . $md_a[2][0] . '">' . $text . '</a>'; - - } else { // text only - - $text = self::htmlEscape($md); - $html = $text; - - } + $text = strip_tags($html); return $clear ? $text : $html; }