Does JupyterLab language registry's addLanguage support LRLanguage as input?

I am trying to add a syntax highlighter and after searching for how JupyterLab declares the default languages, I came across wrapping a LRLanguage from @lezer/generator in the JupyterLab source. Is this a supported way to add a new language support for extensions? I made a basic LRLanguage using the same format as in that file but if I create a fenced code block it doesn’t highlight my code. I am getting no errors in the inspector.

Can I get some help determining what is wrong? My code is posted here: algorithm_plugin.ts, highlight.ts.

1 Like

There are two code highlighters: for code and for markdown. What you did should get you code in a file or code cell highlighted, but for markdown it is a bit more complex (I assume that by “fenced code block” you mean using it in markdown - is this correct)?

Yes, I am looking for markdown highlighting. I do not need file or code cell highlighting. My testing fenced code is simply:

``` algorithm

Could you check that the code block is parsed by your language (you can look at the Dom nodes structure for that)?

Normally that should work. What I think will not work is the highlights because you need to match your token with highlighted token:

If I’m correct, what you will need to highlight you token (aka your tag) is to provide a custom codemirror theme through using that lab plugin

You then create a JupyterLab extension that registers your language with CodeMirror using specific MIME types and file extensions. Ensure your language identifier matches in fenced code blocks for proper integration, and monitor the browser console for any errors to debug effectively.

Looking at the inspector, I can see the HTML and it seems to be appropriately as “algorithm” which is the name I’ve been using.

So assuming I am parsing my fenced code correctly, I should just need to provide a syntax highlighter scheme to CodeMirror which should then get applied to my parsed code?


Or easier, you use token tags that are already highlighted. It means you need to map your token to known tags; see Lezer Setup Example

A list of known tags is available there:

Note: not all tags get highlighted in the default Jupyterlab codemirror theme. Hence the possible need for you to provide your own theme.