[英]Display markdown images as links
I'm using Michel Fortin's PHP Markdown for Markdown converting but i want to show images as links instead of inline. 我正在使用Michel Fortin的PHP Markdown进行Markdown转换,但我想将图像显示为链接而不是内联。 Because anyone can insert a 5MB jpg from Imgur and slow down page.
因为任何人都可以从Imgur插入5MB jpg图像,从而降低页面速度。
How can i change images to link-to-image? 如何将图像更改为链接到图像?
An example of an override would look something like the follwing: 覆盖示例如下所示:
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>";
}
}
Demo: http://codepad.viper-7.com/VVa2hP 演示: http : //codepad.viper-7.com/VVa2hP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.