I have a CodeMirror mode for a language not already covered by CodeMirror (namely Maxima, https://maxima.sourceforge.io). I would like to have it bundled with other CodeMirror modes which are shipped with JupyterLab.
The CodeMirror project is no longer accepting PR’s to implement new language modes; instead they are asking authors to create a NPM package and publish it themselves. So that’s okay by me, however, it’s not clear to me how a new language mode would get included in JupyterLab.
I see that jlpm run build:packages
seems to fetch all the CodeMirror modes which are packaged with the base distribution of CodeMirror, that’s great. How would it be arranged to fetch a CodeMirror mode implemented by a separate package – what should I ask the JupyterLab project to do? I.e., for what file should I make a PR.
I’m guessing that there must be a list of all packages fetched by jlpm
and I guess I’m hoping that someone can point me in the right direction. I’m kind of hung up on the idea of a list of packages, maybe that is not the right way to think about it; if so, again, I hope someone will point me in the right direction.
All the best, and thanks for your help,
Robert Dodier
At present, there is no “standard” way of getting CodeMirror syntax modes added to JupyterLab Core… and as that project is considering fully embracing CodeMirror.next (ne 6) which uses a different syntax highlighting system, it seems like it would be unwise for us to start taking on a potentially uncountable number of language-specific sets of code… which the upstream has also dropped.
Some alternative approaches:
1 Like
Thanks for the info. I should have mentioned that there is a kernel for Maxima (GitHub - robert-dodier/maxima-jupyter: A Maxima kernel for Jupyter, based on CL-Jupyter (Common Lisp k), in which the CodeMirror maxima.js is currently living, and it is installed by patching the CodeMirror installation by hand; I’m looking for a more automatic way to go about it, hence my question here.
You mentioned jupyter labextension build
– I will take a look at this, thanks for the pointer.
But perhaps I’ve missed something. Is there a way to bundle the CodeMirror mode only with the language kernel, avoiding the need to install any files into a system installation of CodeMirror or JupyterLab or anything else? Thanks for any insights.
best,
Robert Dodier
However the maxima package copies files on installation to…
-
$PREFIX/share/jupyter/kernels/maxima/
…it would also need, at build time to have turned…
package.json
index.js # or .ts or whatever
…into the following files, and copy them to…
-
$PREFIX/share/jupyter/labextensions/maxima-mode/ # or whatever
package.json # this gets copied and updated
-
static/
remote.entry.1234abc.js # this gets built by jupyter labextension build
abc1234.js # the actual code
But otherwise: there isn’t really a predictable, simpler way to provide enough information and metadata to JupyterLab or CodeMirror that .some-random-extension
is of MIME type text/x-some-random-type
and should use a syntax mode called Some Random Language
. The jupyterlab-simple-syntax
idea, discussed in the stan
thread, would make that possible, but might be limited to declarative grammars (e.g. CodeMirror simplemode
, nearly.js
, etc.)