Skip to content

deathbeds/jupyterlab-simple-syntax

Repository files navigation

jupyterlab-simple-syntax

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. Binder

Installation

TODO: Maybe release, but for now try your luck with a development installation.

Usage

As a file

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.

As an output

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).

How it works

This (ab)uses the Jupyter MIME renderer specification to turn appropriately- formatted JSON into a syntax highlighting mode.

Development

# 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

Roadmap

  • 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

About

JSON-based syntax highlighting for JupyterLab

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published