artisticat1 / obsidian-latex-suite

Make typesetting LaTeX as fast as handwriting through snippets, text expansion, and editor enhancements
MIT License
1.43k stars 56 forks source link

[FR] Change to a more standard file format to store snippets #66

Open proItheus opened 2 years ago

proItheus commented 2 years ago

Very happy that #39 be implemented! Now I can use ultisnips in vim to quickly creat snippets :smile:.

However, current snippet file use a strange format (array in js?) , thus for syntax highlighting and checking to work, we have to write relevent configs from scrach, which is a REALLY pain...

I think it's better to switch to some more standard formats to solve that. Switch to json may only require minimal effort, though it appears to not support comments?

I'm personally in favor of toml for it's readability and native support of comments. We may specify a snippet like this:

# some comment
[[snip]]
trigger = "mk"
replace = "$$0$"
options = "mA"
artisticat1 commented 2 years ago

Hello!

The snippets are perfectly valid JavaScript, so saving your snippet file as a .js file should give you syntax highlighting. (However, snippets are actually parsed by the plugin using json5. It's an extension of json which adds support for comments among other nice features.)

In the future, I can consider changing the format if there is significant demand.

B4rc1 commented 2 years ago

Is there a way to edit the .js file in Obsidian with syntax highlighting? I know can I view the files in the file explorer by changing Files & Links > Detect all file extensions to true, but then I cannot edit them in obsidian, it opens them in my external editor configured for that filetype.

B4rc1 commented 2 years ago

Well, I found a temporary fix for the problem: Just put it in a markdown file and wrap the code block in javascript block comments like this:

Note I use ' instead of ` here because github really does not like nested codeblocks

/*
'''js
/*

<your snippts>

/*
'''
*/

EDIT: I actually really like this because I can have (one or many) unused snippet section like this:

/*
'''js
/*

<your snippts>

/*
'''

## Unused snippets:

'''js

<your unused snippets>

'''

*/