我正在使用Michel Fortin的PHP Markdown进行Markdown转换,但我希望将图像显示为链接而不是内联。因为任何人都可以从Imgur插入5MB jpg并减慢页面速度。
如何将图像更改为链接到图像?
答案 0 :(得分:1)
覆盖的一个例子看起来像下面这样:
class CustomMarkdown extends Markdown
{
function _doImages_reference_callback($matches) {
$whole_match = $matches[1];
$alt_text = $matches[2];
$link_id = strtolower($matches[3]);
if ($link_id == "") {
$link_id = strtolower($alt_text); # for shortcut links like ![this][].
}
$alt_text = $this->encodeAttribute($alt_text);
if (isset($this->urls[$link_id])) {
$url = $this->encodeAttribute($this->urls[$link_id]);
$result = "<a href=\"$url\">$alt_text</a>";
} else {
# If there's no such link ID, leave intact:
$result = $whole_match;
}
return $result;
}
function _doImages_inline_callback($matches) {
$whole_match = $matches[1];
$alt_text = $matches[2];
$url = $matches[3] == '' ? $matches[4] : $matches[3];
$title =& $matches[7];
$alt_text = $this->encodeAttribute($alt_text);
$url = $this->encodeAttribute($url);
return "<a href=\"$url\">$alt_text</a>";
}
}
答案 1 :(得分:0)
你应该看看Parsedown。这是一个更新的,我相信,更容易扩展Markdown的实施。