jon-heard / obsidian-inline-scripts

Obsidian plugin: Type text shortcuts that expand into javascript generated text.
MIT License
129 stars 4 forks source link

Allow certain shortcuts only to be used in a math environment #7

Closed MohrJonas closed 2 years ago

MohrJonas commented 2 years ago

Hi, I really enjoy your plugin. Would it be possible to add an option to shortcuts, so they can only be used in a math environment (surrounded by $-signs)? Cheers

jon-heard commented 2 years ago

This is definitely doable. I'm wondering if it might be more generally useful (if a bit more effort per-shortcut) to have the line's text and the shortcut text's start and end character positions made available to the Expansion text. That, coupled with the ability to cancel a shortcut, would let an Expansion text determine if it is surrounded by $'s and cancel if it is not.

I'm going to implement that soon. Does it do the trick for you? I can provide an example of how to work with your use-case once it's implemented, if you wish.

MohrJonas commented 2 years ago

Sounds perfect! Looking forward to an example once it's implemented 😁

jon-heard commented 2 years ago

I just put out a new release which includes the ability to do what you want. You can find more info on the release here.

I've also created a demonstration of how you could prevent a shortcut from expanding outside a math block. You can find it here.