首页 > Typecho 1.0 怎么修改为默认新窗口打开?

Typecho 1.0 怎么修改为默认新窗口打开?

o.9 版本可以通过通过 Markdown 编辑器的代码进行修改,到 1.0 后原来的 Markdown 编辑器的相关文件没有了对应的代码,请问怎么解决?


直接写 <a href="url" target="_blank">text</a> HTML 代码吧,Markdown 默认没有新窗口的语法。


http://yijile.com/log/494.html
手机不方便打代码,有劳自己看一下
修改HtmlRenderer.php文件文件,然后补充一句,楼上通过jq增加nofollow是无意义的,搜索引擎抓取的是源代码而不是js二次渲染的结构。


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

主题中有JQuery库的话,还挺方便解决的,没库就用原生js吧。

这段代码的意思是,在内容部分寻找a标签,为其添加新窗口属性。同时检测其中不包含本网站的域名,添加nofollow……你可以稍微修改下,比如非本站链接才加_blank

$("#content").find("a").attr("target", "_blank").not("[href*='xxxxx.com']").attr("rel", "nofollow");
【热门文章】
【热门文章】