Using the library
This commit is contained in:
parent
67ec67d50f
commit
1c633d74d9
@ -134,30 +134,13 @@ class Utils {
|
||||
}
|
||||
|
||||
public static function markdown($md, $clear) {
|
||||
preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $md, $md_a_img); // Markdown [![alt](src)](href)
|
||||
preg_match_all('/!\[(.*?)\]\((.*?)\)/', $md, $md_img); // Markdown ![alt](src)
|
||||
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] != '') { // [![alt](src)](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] != '') { // ![alt](src)
|
||||
|
||||
$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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user