I just wrote the Code Section plugin - a content plugin. It listens for code section fences, reads the requested file's content, renders it on behalf of the original fence rule and finally returns the new content to be displayed - all of it in a synchronous manner.
Now I'm faced with the following problem: I want to make the reading code asynchronous. For instance I want to fetch code sections from a web source. But fetch is asynchronous: it returns a Promise and if I provide a callback and the callback is called, the original rule invocation is over - I no longer have the chance of delivering my rendered code file as return value. So how can I do that: deliver the rendered markdown after rule invocation?
Can you help?
Thanks - Jürgen
New problem with same plugin
Hi,
I'm faced with a new problem for the same plugin. The problem is: when I export the content of a note to PDF, the folder of an embedded resource is not recognized anymore. Further the content of my CodeSection fence is changed before any rendering as if it were a resource link. The embedded resource and its folder are required for rendering of a piece of code from that resource.
The plugin works as follows:
- It establishes 2 hooks into the rule chains. One is a link_open rule and a second one is a fence rule
- The link_open rule tries to detect the path of embedded resources
- The fence rule extracts a piece of code from such a resource and renders it on behalf of the original fence rule
The detection of the resource path is not working anymore during PDF export. This could be a Bug in Joplin or the handling is different by design. Anyway, the analyzed resource link does not contain the resourceFullPath in this case.
This is all documented in the appended Joplin console log.
The problem with the Joplin API is that I did not find a way to transfer information from the plugin to the markdownit script. All I found transferred information from the WEBVIEW to the plugin and vice versa. A possibility to perform such a transfer could be a great help.
Can anyone help?
Thanks
Joplin-01.log (10.6 KB)
1 Like