谢谢您的回复!
我今天下午偶然发现了您的第一个链接。
GitHub 链接中的文件已有 7 年历史了,所以我猜代码可能已过时?
无论如何,我使用了这个:
export function setup(helper) {
if (!helper.markdownIt) { return; }
helper.registerOptions((opts, siteSettings) => {
opts.features.nolinkify = siteSettings.no_linkify_enabled;
});
helper.allowList(["span.nolinkify"]);
}
这是我从 GitHub - unfoldingWord/discourse-mermaid: Adds the Mermaid JS library to discourse 借用的
我的插件只有几行代码,我不太清楚它在做什么,以及是否所有代码都是必需的,但至少我可以添加带有 nolinkify 类的 span。
在我的例子中,目的是使用 Auto-Linkify Words 轻松地“取消链接”帖子中的单词(它只接受标签和类来防止链接化),尤其是在使用 DiscoTOC - automatic table of contents 时,在标题 HTML 标签中取消链接单词。
我还尝试了一个基于 bbcode 语法的解决方案,如下所示:
helper.registerPlugin(md => {
md.inline.bbcode.ruler.push("nolinkify",{
tag: "nolinkify",
replace: function(state, tagInfo, content) {
const token = state.push("html_raw", '', 0);
const escaped = state.md.utils.escapeHtml(content);
token.content = `<span="nolinkify ">${escaped}</span>`;
return true;
}
});
});
因此,我尝试了这两种解决方案来解决我的标题标签问题(与目录表相关)。
这不起作用:
## [nolinkify]test[/nolinkify]
但这有效:
## <span class="nolinkify">test</span>
我更喜欢第一种语法,但我想它与目录表不兼容,因为脚本的执行顺序……