Using the library
This commit is contained in:
parent
67ec67d50f
commit
1c633d74d9
@ -134,30 +134,13 @@ class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function markdown($md, $clear) {
|
public static function markdown($md, $clear) {
|
||||||
preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $md, $md_a_img); // Markdown [![alt](src)](href)
|
$parseDown = new \Parsedown();
|
||||||
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)
|
|
||||||
|
|
||||||
$text = self::htmlEscape($md_a_img[1][0]);
|
$html = $parseDown
|
||||||
$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>';
|
->setMarkupEscaped(true)
|
||||||
|
->line($md);
|
||||||
|
|
||||||
} elseif (isset($md_img[2][0]) && $md_img[2][0] != '') { // ![alt](src)
|
$text = strip_tags($html);
|
||||||
|
|
||||||
$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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $clear ? $text : $html;
|
return $clear ? $text : $html;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user