Is there a prism language definition for Typst?

Does anyone know whether someone has already created a (sophisticated) Typst language definition for Prism (prismjs.com)?

I would like to add some syntax highlighting to a package documentation page.

I’m not aware of that, but what do you want to achieve? Do you want to highlight Typst code with Prism in some HTML page? Or do you want to highlight some language code inside a Typst document?

In case you want to highlight code by using Typst, you can already do that with raw.lang. Or if some language isn’t supported yet, you can add your own definition by using raw.syntaxes, which uses sublime-syntax file format.

I don’t think so!

In any case, I believe Prism is used by GitLab to highlight code. ATM, Typst code is not highlighted correctly in my institutional instance… Grr!

@Mc-Zen if you contribute a Prism definition for Typst, I’ll be glad to hear of it, don’t hesitate to mention me!

Okay, I will haha. But I’ve never created a language definition for prism so far :D

Yes, that’s the goal.

Hi @quachpas ,

good news! I implemented a language definition for Prism. It’s not perfect of course and has certain limitations. Typst is a language that is notoriously bad for regex parsing (due to the three languages – markup, code, math – baked into one where you may switch from each to the others at anytime) and regex is all that is supported by Prism.

But it works pretty well now for sane cases – and one might argue that the purpose of displaying code in the web is mostly to demonstrate examples that are not too convoluted (hopefully :sweat_smile:).

The thing is: I don’t really have the capacity for maintaining it, at least not on my own and it would be necessary to write some test cases for it.

3 Likes

Amazing @Mc-Zen, if you publish your work maybe someone might continue your contribution. Do you have a repository?

I’m already working on it :)

1 Like

Here it is :tada:

Mc-Zen/prism-typst: Syntax-highlighting Typst code with Prism (github.com)

2 Likes