编辑 \var\CommonMark\HtmlRenderer.php,从 104 行开始:
case CommonMark_Element_InlineElement::TYPE_LINK:
$attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
if ($title = $inline->getAttribute('title')) {
$attrs['title'] = $this->escape($title, true);
}
$attrs['target'] = '_blank'; //添加这一行
return $this->inTags('a', $attrs, $this->renderInlines($inline->getAttribute('label')));
注意我打了注释的那行。Typecho 版本 1.0 (14.10.10)。来源于 Kent。
[...][2]: http://example.com/2这次偶然点了自己博客文章的链接才发现,这样会把可选的 title(即上面引号里的内容)当作链接一块解析。过程中会去除不安全的特殊符号,最终会变成指向 http://example.comexample 之类的超链接。搜了一下网上和 issue 没有人提,确定了 Markdown 是有这种语法,不想一个个改文章链接,遂自己从源码层面解决。最开始按照我[...]