Typecho默认的a标签是只有href属性的,也就是覆盖本页打开。
但是大多数情况下我们都希望链接从新窗口或新标签页打开。

默认html

下面是默认的html代码。

<a href="https://www.ipaddr.host">
千思网
</a>

希望的html

页内链接不仅要从新窗口打开,而且从seo方面考虑,我们还希望为站外的url添加nofollow属性。
那么要达到上述的效果,html代码应该是下面这样的,增加了target="_blank" rel="nofollow"

<a href="https://www.ipaddr.host" target="_blank" rel="nofollow">
千思网
</a>

变更typecho代码

要达到上述效果,可以直接更改typecho的php代码。
修改/var/CommonMark/HtmlRenderer.php文件。

修改前

下面是修改前的代码

104             case CommonMark_Element_InlineElement::TYPE_LINK:
105                 $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
106                 if ($title = $inline->getAttribute('title')) {
107                     $attrs['title'] = $this->escape($title, true);
108                 }

修改后

下面是修改后的代码,请将107行中qiansw.com替换为你的域名。

104             case CommonMark_Element_InlineElement::TYPE_LINK:
105                 $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
106                 $attrs['target'] = $this->escape("_blank", true);
107                 if ( !substr_count($attrs['href'],"qiansw.com") ) {
108                     $attrs['rel'] = $this->escape("nofollow", true);
109                 }
110                 if ($title = $inline->getAttribute('title')) {
111                     $attrs['title'] = $this->escape($title, true);
112                 }

最终效果

指定域下面的连接不加nofollow,站外链接加nofollow

<p>
<a href="https://www.ipaddr.host" target="_blank">千思网</a><br>
<a href="http://www.baidu.com" target="_blank" rel="nofollow">百度</a>
</p>