Hi,
I'm just working on a markdownIt Plugin. I need access to a resource file to render its content. But I had no success to deliver the data directory from the plugin index file to the content script. The trial was to add to the interface of the content script and invoke a setDataDirectory function.
The error message was always: No Loader for this source or the like when I built the modified plugin.
All other functionality is already working when I hard code the required directory location.
I don't think you need to do this because all the resources will already be accessible by the markdown-it plugin. For example you could add a rule for images or for link_open and check their src or href attribute. That's where the resource path would be.
I believe, this was a misunderstanding. I already have the resource id . What I want to do is to open the (text) file and extract some information. But the href from token is only the id without path. How do I get the path?
I get this message without path:
Error: ENOENT: no such file or directory, open './21f1d4c945174e16b8b5183f685afc5c.py'
Problem solved! What I did not know: '.' already references the data directory. So I can access the file (for instance) with '../reources/xxx.py' where xxx is the id of the file.
Hmm, that's not ideal because there's no guarantee that the folder will be there, it's basically internal stuff.
I'm pretty sure the full path to the resource appears somewhere during rendering, otherwise it wouldn't be possible to display images or other attachments. So it should be possible to grab that path and do whatever processing you need.
(I'm unticking the "solution" tag because I prefer it doesn't become the norm to access the resources)
I solved the problem more or less. In link_open rule I check the links object in ruleOptions.context.currentLinks for a local resource entry. It must be done after invoking the app version of link_open, otherwise I do not get an entry.
The entry has an attribute resourceFullPath, which I can use.
Not even intuitive, but it works. Wouldn't it be better to provide an option or context entry with just the location of the resources directory or its parent?
Wanted to ask about your implementation, but found your repository instead. I also needed this function and went down the same path, but your solution is much better. Thank you for discovering it.