How to implement a Markdown Plugin?

I've done some looking around (as I've recently come across Joplin.. I was developing an application that basically did all the same things as Joplin in my spare time so I've decided to save myself the effort and just add the features on to Joplin that I'd like :stuck_out_tongue: ). I've done some looking around at the regular plugin API as well as at how markdown plugins were originally implemented (via this issue) and I have a few questions.

Is it possible to add and install a markdown-it plugin via a regular Joplin plugin? If not, would it be a good idea to add support for it? Or should I look into adding a plugin like this via a pull request?

To clarify functionality I want to add, the application I was building was built around the flexmark(link removed and posted below.. new poster limit :confused:) markdown parser. One of the plugins it has is the "attributes"(link removed and posted below.. new poster limit :confused:) plugin, which would be the plugin I would recreate (after I take some time to make sure it doesn't already exist for markdown-it. This is just a preliminary investigation on my part to see what is possible inside of Joplin's ecosystem).

I was using my prototype application with that parser and plugin to add <span>s with class attributes.. though the attributes plugin linked above can do more than that. Ultimately, I want to convert this:

{.classA} This is a <!---->test{.classB}. Look at it go!

It also supports this.{.classC}

And <!---->this{#this} though I've never used it much.

Into this:

<span class="classA">This is a <span class="classB">test</span>. Look at it go!</span>

<span class="classC">It also supports this.</span>

And <span id="this">this</span> though I've never used it much.

I've got a bunch of markdown (like three years worth) that use this pattern, in combination with custom CSS, to stylize certain blocks of text. I'd like to bring it over if possible. I'm also open to alternatives if there's other ways to get custom classes applied to blocks of text (though I don't care much for the admonition plugin's formatting..)

Any thoughts?

Here's the link to flexmark
The attributes plugin can be found there at "flexmark-ext-attributes"

Yes it's possible to implement this type of plugin! I think there might already be a markdown-it plugin for it as well.
These types of plugins use something called content scripts in Joplin, you can see an example here.

Essentially this type of plugin is just some boilerplate wrapped around a markdown-it plugin.


Thanks!! That example will definitely help me figure things out.. And I did some looking this morning and found "markdown-it-attrs" so the plugin already exists.. just gotta hook it up. :slight_smile:

The only question I have now, though, is if I should make a plugin or if I should look into adding it directly into the markdown "plugins" settings menu as a toggleable, embedded option. That might be easier as a start so maybe I'll try that and put in a PR, see if it gets accepted or rejected.

Unless you or anyone watching this thread has any thoughts. :stuck_out_tongue:

(side note: why is this system so hostile against new posters and links? Now it's not letting me include any. It's bizarre.. I was trying to link to the npm page for markdown-it-attrs but it wouldn't let me. :confused: )

Maybe it's because you're posting a topic for the first time, maybe the system is trying to avoid someone posting an advertising link

You can surround urls in backticks to still post the links without them being urls, it is to stop spam.

1 Like