给爸爸在网上弄了一个文章集子,用的是typecho系统。

但是由于编辑器是markdown语法,默认的情况对于文章内的超链接是不能新窗口打开。要想设置成新窗口打开,就只能写一段冗长的html来解决。

另外还需要加上rel='nofllow',它的作用是告诉搜索引擎,不要将该链接计入权重。因此多数情况下,我们可以将一些不想传递权重的链接进行nofllow处理。

这些设置对于markdown语法本身并没有计及上去,因此需要改typecho系统的文件。

需要更改的文件位于\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')));

这里是针对超级链接的处理。我们将添加两行代码,变成下面这个样子:

        case CommonMark_Element_InlineElement::TYPE_LINK:
                $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
                $attrs['target'] = $this->escape(_blank, true);
                $attrs['rel'] = $this->escape(nofollow, true);
                if ($title = $inline->getAttribute('title')) {
                    $attrs['title'] = $this->escape($title, true);
                }

完。

最后修改:2021 年 07 月 29 日
如果觉得我的文章对你有用,请随意赞赏