# Question about scope and potential feature request

After using Joplin for awhile to take notes, specifically for physics where I have to type long equations with a lot of repeated KaTex syntax, I've come to the realization that having a shorthand for words would be helpful. Instead of writing "\overrightarrow" in front of every vector, I could just have a keybind to "paste" it in.

I looked at the API for a bit and thought it was possible so I started writing it, but I soon realized that plugins do not have direct access to the DOM. I switched tracks into trying to make a sort of autofill plugin, akin to most code editors but with KaTex syntax. AFAIK this also isn't possible since it's outside the scope of contentScripts and I wouldn't be able to render a window on the body of the note. I could probably achieve something similar with a modal but at that point it would just be more effort to click something on the screen then to just write it; I want to speed up the process (even if it's only be a few fractions of a second, it adds up), not slow it down.

So I guess my question is: am I wrong? Could this technically be possible?
If not, I'm trying to think of a way that would be able to do either of these things without the stated security and performance risks stated in the docs. For the former idea, it could be entirely possible if there was a listener built in to handle keyboard events. This wouldn't pose a security risk if it was only over the note body because you can already do essentially the same thing by using onNoteChange() and just getting the new characters. I guess I could do that, however I'd like to use modifiers for UX.

The aforementioned autocomplete idea, in my opinion, has a lot of potential uses. Perhaps if something native was introduced to allow this behavior in plugins, it could be expanded on quite heavily and improve UX as there are a lot of heavy syntax based languages used inside of Joplin.

If you're typing in the Markdown Mode (split window) then you can use this plugin to do just that (spoiler: I'm the developer).

You need to prepare a list of KaTeX string you want to autocomplete then create one or multiple String Command for it. The configuration is a bit annoying but if you can code then this shouldn't be a big problem.

Oh yeah that could definitely work for making shortcuts for KaTex. I’ll check it out when I can.

On another note, since you’re rendering things over the note Split View window, does this mean that you can manipulate the DOM over notes with contentScripts codeMirror? I must have misinterpreted it because I thought that it was only for rendering the markdown in the side panel, not for the editor. I haven’t dug any deeper into the API other than just the docs since I’m pretty busy right now and thought this was going to be a quick project (never is).

Short answer: Yes. But I only follow and used an established add-on/example of CoreMirror so I don't know much.

There are currently two content script types. CodeMirrorPlugin and MarkdownItPlugin. CodeMirror is the markdown editor used by Joplin, and MarkdownIt is the renderer.

Using the CodeMirror content script, you can add some things to the DOM, but can't arbitrarily manipulate it (although you can arbitrarily manipulate the nodes you add). For example, you can see in my plugin, rich markdown that it's possible to add images inline to the markdown editor.

Ah okay. When I read through I understood it as CodeMirror being the markdown code renderer for some reason. Thanks for the clarifications!

1 Like

One last question since I’m going to be developing in Joplin more: is there any way to access the plugin environment from devtools for live testing?