Accessing Joplin model from CodeMirror plugin

I am writing a plugin that installs a CodeMirror content script (for inline tags). From the content script I need to get the list of all tags. Is there any way to achieve this?

I don't think there currently is (but there is a placeholder for passing data to content scripts).

What are you looking to do in the content script? I might be able to help you find a work around.

I was hoping to make a plugin that'd allow the user to add tags by typing # and either selecting an existing tag from the list or creating a new one.
Got CodeMirror to show autocomplete popup:
image

and then I realized there does not seem to be a way to get the list of all tags, add a tag to the current note, and create a new tag.

The only way I can think of is call into clipper API over http but this seems like a terrible solution, and I am not going to do this.

1 Like

Similarly, I was thinking of another plugin that could benefit from having access to data API.
This time a MarkdownIt plugin allowing the user to write something like
'''search:
''' (but with 3 backticks - can't figure out how to escape them)
and have it rendered as a list of links to the notes matching the query.

Posible you can use the GET /tags Data API in the script and not the plugin API?
https://joplinapp.org/api/references/rest_api/#get-tags-id

dow, I see you have you have mentioned this ...

It would also help with this feature:

I see, this is a really good use case for passing data. I think we should wait to see what @laurent says about it.

Personally, I don't see using the data api to be much of an issue, but it would be good to have an official stance in either case.

Somewhat offtopic, but I find the idea of one function calling another function in the same process over http a little ridiculous, it's like microservices taken to the extreme.

The ideal solution would be to be able to post messages between the content script and the plugin. That way you indirectly have access to the whole API, and also can pass messages whenever needed.

The issue with ipc calls though is that they are always async. So I'm wondering, in the tag example above, would it be possible to get it working with async calls? I'm not very familiar with the way CodeMirror works, but I guess most calls are sync? Basically I'm wondering if it's even worth looking at posting messages if it doesn't end up solving the issue.

I believe CodeMirror supports async calls for autocomplete. I couldn't get it to work in the 1st attempt though and haven't tried since.

I've just realized - I can't even use http API. It requires the port and API token but there's no way for a content script to get them (except maybe reading the database directly).

@roman_r_m or @CalebJohn, do you have a simple CodeMirror content script example I could use to test posting messages?

Sorry, I don't have anything that needs it yet. You can use the math plugin as a base. line 344 shows the plugin setup.