[IPython-dev] how to implement syntax highlighting for a new language

Thomas Kluyver takowl at gmail.com
Sun Aug 9 17:44:57 EDT 2015


On 9 August 2015 at 14:14, Robert Dodier <robert.dodier at gmail.com> wrote:

> I gather that nbconvert uses pygments for syntax highlighting. It
> looks like I could easily create a highlighter for Maxima by modifying
> the one for MuPAD (a similar system). How can I tell IPython to use
> the new highlighter?
>

Set up your lexer correctly as a pygments plugin:
http://pygments.org/docs/plugins/

And make sure that its name (or an alias) matches the language_info.name
you give in your kernel_info_reply.

If you can't use that same name for some reason, you can also specify
another language_info.pygments_lexer name in kernel_info_reply:
http://jupyter-client.readthedocs.org/en/latest/messaging.html#kernel-info


> I haven't been able to figure out how the browser does highlighting.
> Fishbowl (Common Lisp kernel) has some custom Javascript which
> apparently implements a highlighter based on CodeMirror. Is that the
> usual way to go for new languages?
>

Codemirror is the JS text editor we use for notebook cells. Many kernels
can just specify one of the modes codemirror already provides:
https://codemirror.net/mode/

If there isn't a suitable mode already in codemirror (it doesn't look like
there's one for Maxima), you'll need to provide one. You can do this in a
kernel.js file alongside kernel.json. (This doesn't seem to be documented
yet - I've made an issue for that:
https://github.com/jupyter/notebook/issues/265 ).

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150809/c807418f/attachment.html>


More information about the IPython-dev mailing list