wodeni / obsidian-penrose-plugin

A plugin for Obsidian that allows you to make diagrams with Penrose (https://penrose.cs.cmu.edu/).
MIT License
2 stars 1 forks source link

Add syntax highlighting for Substance #2

Open wodeni opened 8 months ago

wodeni commented 8 months ago

obsidian uses prism for syntax highlighting, and it'd be great to add a simple grammar for Substance as a starter.

Penrose has monaco grammars and textmate grammars for all three languages. The current state of syntax highlighting within Penrose isn't too great, as there are code duplication across these two sources and none of them are very complete. Hopefully it's not too difficult to port the textmate grammar over to prism.

adityakanu commented 8 months ago

I attempted to integrate the Textmate grammar for Penrose's substance into Prism for syntax highlighting. Here's a preview:

image

I have also added some keywords from styles since they are used while writing substance.

You can look at the code here: https://github.com/PrismJS/prism/compare/master...adityakanu:prism-penrose:master

@wodeni would like to hear your thoughts on this, let me know if there's anything you'd like me to adjust or focus on.

wodeni commented 8 months ago

thanks for the quick update @adityakanu! my preference would be to include the Substance grammar for now, as it's the main interface for making diagrams in obsidian and their might be some conflicts between Substance identifiers and Style keywords.

i haven't thought much about using obsidian as the main authoring environment for style and domain though. one thing i'll note is we're thinking about merging the three languages to have one unified grammar, so this approach may work out in the medium term.

adityakanu commented 8 months ago

I agree. Let's keep it to substance grammar for now. I will make the necessary changes and let you know for review.

adityakanu commented 8 months ago

Have a look: https://github.com/PrismJS/prism/commit/cd3405ca718d0889916c2dadcc67d0d851ff3300

I made a minute mistake in the latex regex so fixed it in a separate commit.