Simple, customizable syntax highlighting for JupyterLab, powered by CodeMirror's simplemode JSON and codemirror-textmate
This is not meant to be particularly useful yet, but rather is about exploring data-driven ways to capture syntax highlighting.
TODO: Maybe release, but for now try your luck with a development installation.
The file type .simplemode.json
is registered automatically after installing
the extension.
{
"mime": "example",
"ext": ["example"],
"mode": "example",
"name": "example",
"states": {
"start": [{"regex": "\\d+", "token": "number"}]
}
}
Similarly, any TextMate language JSON file (also used by Sublime Text, Atom, or VSCode) can be loaded.
From a kernel launched with JupyterLab, display a
application/vnd.jupyter.simplemode.v1+json
JSON object, such as with IPython:
display({"application/vnd.jupyter.simplemode.v1+json": {
"mime": "example",
"ext": ["example"],
"mode": "example",
"name": "example",
"states": {
"start": [
{"regex": ".*", "token": "meta"}
]
}
}}, raw=True)
Now, you should be able use the new mode.
While this could be useful for generating little toy syntax highlighters, a more robust implementation could allow a kernel at startup time to register its own custom syntax(es).
This (ab)uses the Jupyter MIME renderer specification to turn appropriately- formatted JSON into a syntax highlighting mode.
# clone the repo
# get jupyterlab and nodejs
jlpm bootstrap
Other things:
jlpm watch # continuously rebuild extension
jupyter lab --watch # continuously rebuild lab in another terminal
- Make work with side-effective MIMERenderer in JupyterLab
- Add a real schema with ajv
- Make a nice authoring/testing interface
- Integrate with JupyterLab settings
- Make a nice visualization
- Release on
npm