My markdown extension works in preview but not on cooked

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?

2 Likes

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:

https://github.com/discourse/discourse/blob/56a9f777cb54fdf1ce21fd605297d8f51a1398dd/lib/pretty_text.rb#L96-L98

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

6 Likes

That fixed it. Thank you Sam.

3 Likes

I have the same problem when trying to override the fence renderer (md.renderer.rules.fence) — it works in the preview window, but the default Discourse render is shown after submission.

Here is the code:

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">Copy and paste this code into n8n to play with the workflow</div>' +
               tokens[idx].content +
             '</div>'
    };
  });

}

You can also see the full plugin structure here. Any help would be greatly appreciated!

1 Like

Did it ever work for you?

In my case, I have it in the right folder /assets/javascripts/discourse-markdown and it is still showing only in the preview.

For some other people, it worked after a while, which makes me think that they reloaded the server. I did that too and no luck.