简体   繁体   English

所有链接的自动 {target=_blank}

[英]Automatic {target=_blank} for all links

I have found this script that can add the blank feature to each link in html.发现这个脚本可以为html中的每个链接添加空白功能。

(function() {
    var hostname = window.location.hostname;
    var new_tab = true;
    var set_icon = true;
    for (var links = document.links, i = 0, a; a = links[i]; i++) {
        if (a.hostname !== hostname) {
            if (new_tab)
                a.target = '_blank';
            if (set_icon)
                a.innerHTML +=
                    '<i class="fa fa-external-link fa-1 external-link-margin" />';
        }
    }
})();

Is there any way how I can make it work automatically on html generation form md files in Pelican static blog engine?有什么办法可以让它在 Pelican 静态博客引擎中的 html 生成表单 md 文件上自动工作? So that it is added to every html file and modifies the links.以便将其添加到每个 html 文件并修改链接。

I found a Python-Markdown extension Phuker/markdown_link_attr_modifier which does exactly what you want.我找到了一个Python-Markdown扩展Phuker/markdown_link_attr_modifier ,它完全符合你的要求。 In fact, it can be configured to add any attribute to generated <a> tags.事实上,它可以配置为向生成的<a>标签添加任何属性。

According to the readme, just run pip command to install it, and add it to MARKDOWN variable in the pelicanconf.py file as an extension.根据readme,直接运行pip命令安装,并在pelicanconf.py文件中的MARKDOWN变量中作为扩展名添加即可。 I tried in my Pelican blog, and it works good.我在 Pelican 博客中尝试过,效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM