Async Markdown-It plugin

Hello everyone. It's been some time since I created the "Bible Quote" plugin. Recently I saw that support for mobile plugins is becoming a thing, and someone suggested that I make my plugin mobile-compatible.

The thing is, currently my plugin works by accessing the file system to open some files, which I see is not supported on mobile. My approach was to load the files from a note instead, using the Data API. This seemed to work fine, the problem now is that loading the files and then sending the parsed objects to the markdown-it plugin (using the localstorage plus a hack) is an async operation that ends after the markdown has already finished rendering. This is "fixed" by refreshing the note: changing from one note to another, modifying the note, etc.

I have tried the following solutions:

I tried the approach of an async rule as suggested in the official md docs, but since Joplin triggers the render function internally, I figured it would be impossible to do this just from the plugin itself. Also, I don't think that replacing the render function from the MarkdownIt instance to be async would be appropriate.
This approach would solve the problem of sending the files over to the markdown-it plugin, and instead just load them from the main plugin and send small messages from the markdown plugin to the main plugin when a query to a file is needed.

My second approach was to reload the note after the files were sent (spoiler: I couldn't trigger a reload manually).

I'm open to any suggestions.

1 Like

One option could be to add the rendering script as an asset, then render quotes after the main note is rendered.

This is similar to what the Function Plot and Extra Viewer Settings plugins do. It's then possible to communicate with the main background script using webviewApi.postMessage(contentScriptId, data) (example, docs).

1 Like

Yep, that's exactly what I need, it just wasn't clear enough to me how to do it. I'll give it a try.
Thanks a lot!

Hi, do you have the King James Bible within your created "Bible Quote"?

Take a look at this repo

1 Like

Thank you, but I was able to download the software yesterday evening and save the kjv version to OS something and added the path but I#m not sure what I need to do afterwards? Sorry, I learn as i need something.

I have Bible Quote and Joplin Bible Notes but all i'm getting is all my notes under Bible headings?

Sorry, Thank you, I worked it out. It's Brilliant!!

1 Like