我的 Markdown 扩展在预览中有效,但在渲染后无效

I have followed these instructions to create a Block BBCode markdown extension for Discourse.

The plugin works when previewing and editing a topic. However, when I actually post the Topic, the raw BBCode mark up appears in the post completely unprocessed.

Is there something I need to do to make sure the plugin operates on posted topics?

I’ve had this happen due to importing modules using Javascript import statement, and the differences in paths between the browser and the mini_racer.

Can you share your plugin code so we can help you to debug?

Thank you for the reply Rafael.

The plugin’s code is here:

As you can see it is very simple. I am using ES Module imports, but only for adding a button to the editing bar. The Markdown extension (https://gitlab.com/textblaze/discourse-snippets/blob/master/assets/javascripts/lib/markdown-it/snippets.js.es6) doesn’t import anything.

I think this is simple naming issue due to:

Move it from markdown-it to the discourse-markdown directory.

That fixed it. Thank you Sam.

我在尝试覆盖围栏渲染器(md.renderer.rules.fence)时遇到了同样的问题——它在预览窗口中有效,但在提交后会显示默认的 Discourse 渲染结果。

以下是代码:

export function setup(helper) {
  if (!helper.markdownIt) return;

  helper.allowList(['div.embedded_workflow', 'div.embedded_tip']);

  helper.registerPlugin((md) => {
    md.renderer.rules.fence = function (tokens, idx, options, env, slf) {
      let content = tokens[idx].content;
      return '<div class="embedded_workflow">' +
               '<div class="embedded_tip">将此代码复制并粘贴到 n8n 中以体验工作流</div>' +
               tokens[idx].content +
             '</div>'
    };
  });

}

您也可以在此处查看完整的插件结构。任何帮助都将不胜感激!

它曾经对你有用吗?

在我的例子中,它在正确的文件夹 /assets/javascripts/discourse-markdown 中,但仍然只在预览中显示。

对其他人来说,它过了一会儿才起作用,这让我认为他们重新加载了服务器。我也这样做了,但没有成功。