html5链接打开新页面,Typecho 1.0 Markdown文章链接从新窗口中打开(target="_blank")

"本文介绍了如何在Typecho 1.0版本中修改Markdown解析器,使得超级链接在新窗口打开。通过编辑varCommonMarkHtmlRenderer.php文件,在104行附近添加`target="_blank"`属性,可以实现链接在新标签页中打开。同时,如果需要添加`rel="nofollow"`属性,也可以参照同样的方法进行操作。"
摘要由CSDN通过智能技术生成

Typecho很好用,但是原生Markdown有一个缺陷,超级链接默认在当前页跳转。如果在文章中添加了参考链接,阅读起来就很不方便。

在Typecho 1.0版本中,要给文章的超级链接添加 target="_blank" 属性其实也是相当简单的。

在 \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);

}

return $this->inTags('a', $attrs, $this->renderInlines($inline->getAttribute('label')));

这就是处理超级链接的部分,我们只要添加一行$attrs['target'] = '_blank';即可: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')));

当然,如果你想加上rel="nofollow"也依葫芦画瓢即可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'; #在新窗口打开属性

$attrs['rel'] = 'nofollow'; #添加nofollow属性

return $this->inTags('a', $attrs, $this->renderInlines($inline->getAttribute('label')));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值