Markdown-it renderer - execute js code upon loading

I have a markdown-it content script that contains a rule like this:

markdownIt.renderer.rules["some_token_name"] = function (
) {
   return "<tag>some custom content</tag>";

I want to execute some js code when the above tag gets rendered by the note viewer. I tried including a <script> tag but it does not work (it does not throw errors but the code is not executed).

The only workaround I found (here) that was working correctly was to include the js code like this:
<style onload="some js code" />
This executes the JS code but, for some reason, the note viewer does not render anything after the first token that contains the <style> tag.

Does anybody know a trick to solve this issue?
Thanks in advance.

Couldn't you get this working by adding the JS file as a plugin asset? For example like it's done in the Mermaid plugin: joplin/mermaid.ts at dev · laurent22/joplin · GitHub

1 Like

It looks good overall, I'll see what I can do.

document.addEventListener('joplin-noteDidUpdate', () => {

Is this a standard event added by Joplin? If this is the case, should it be added to the documentation?

Yes that's a Joplin event and yes if you'd like feel free to create a PR to add the documentation for it. I guess it could go somewhere in the content script doc.

1 Like