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.
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)?
Hello,
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.
Thanks
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?
I’ve modified my extension to add a custom theme to the theme registry, but it still isn’t working. I updating my Lezer highlighter to use tags seen in jupyterHighlightStyle so I can reuse it. I am seeing no errors or warnings on compilation or when I create fenced code in Markdown using my above template. When I create a .algorithm file for testing, I see that the Algorithm language is chosen, but I don’t see any highlighting.
Can you expand on what you mean about checking the DOM to ensure the language is getting properly recognized? I worry that while the language is recognized, the parser is failing somehow. To make testing easier I changed the grammar to be the Lezer example.
What do you mean by this? Do you mean how I am adding the syntax highlighting in the .grammar given to Lezer?
To be included in JupyterLab, your JavaScript assets are bundled using webpack under the wood. The link within the CodeMirror lezer grammar is definitely ignored by webpack. So I’m not sure the code get properly packaged.
So using your example I was able to create a Markdown parser, and while it compiled correctly once, when I try to re-compile my project I get a type error complaining about how 2 of the same types aren’t actually the same. I am not terribly familiar with TypeScript but it seems it is because I am getting the LRParser from @jupyterlab/codemirror and @lezer/lr but I am not sure how I can convince Typescript they are the same.
I am using jlpm. I manually added the line you mentioned but am still getting the same error even when doing a clean build. Is there anything additional I need to do?
I ran those commands and now am seeing the following in addition to the previous errors:
error TS2688: Cannot find type definition file for 'cookie'.
The file is in the program because:
Entry point for implicit type library 'cookie'
error TS2688: Cannot find type definition file for 'cors'.
The file is in the program because:
Entry point for implicit type library 'cors'
error TS2688: Cannot find type definition file for 'karma'.
The file is in the program because:
Entry point for implicit type library 'karma'
That got it compiling yesterday but I opened my project and now the project compiles but I am getting the following error. This is when I try to open the file that contains my custom syntax. I had an issue in my index.ts where somewhere in my git rebasing I lost the part where I actually provide the extension.
The only thing different is that my laptop was restarted between yesterdy and today. Do you know if there are any Jupyter scripts or options I can use to find the source of this error?
How do I use the new CodeMirror theme I create? I added one with the following code but I am not seeing any updates to my syntax highlighting. Do I need to associate the language with the theme?