我正在使用Docusaurus,并希望在新标签页中打开外部链接。 我更喜欢使用代码来解决这个问题,而不是按照这个答案在我的markdown文档中编写html代码的解决方案。
我尝试了这个答案:
[link](url){:target="_blank"}
以及这个答案:
[Google](https://google.com" target="_blank)
我认为这篇文章可能会满足我的需求,我尝试将代码添加到_index.js中,但Docusaurus停止构建。
脚本似乎已经加载,但是没有按照预期工作。
我期望以Markdown格式编写的链接在新的浏览器标签页中打开:
我尝试了这个答案:
[link](url){:target="_blank"}
以及这个答案:
[Google](https://google.com" target="_blank)
我认为这篇文章可能会满足我的需求,我尝试将代码添加到_index.js中,但Docusaurus停止构建。
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
我将JavaScript代码上传到GitHub,并将其添加到siteConfig.js
中:
// Add custom scripts here that would be placed in <script> tags.
scripts: [
"https://buttons.github.io/buttons.js",
"https://msdcanderson.github.io/docusaurus-open-link-new-tab.github.io/open-link-new-tab.js"
],
脚本似乎已经加载,但是没有按照预期工作。
我期望以Markdown格式编写的链接在新的浏览器标签页中打开:
[the rmarkdown website](https://rmarkdown.rstudio.com)
有任何想法都可以,非常感谢。