Jupyter-book: Syntax highlighting for non-python kernels in code-cell directive

Created on 15 Aug 2020  ยท  12Comments  ยท  Source: executablebooks/jupyter-book

Consider the following .md file

````markdown

jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
format_version: '0.8'
jupytext_version: 1.4.1+dev
kernelspec:
display_name: Coconut
language: coconut

name: coconut

{code-cell} coconut range(10) |> map$(pow$(?, 2)) |> list
````

Changing the kernel to coconut works, as can be seen in the rendered image below.

image

But the syntax highlighting does not. Is it possible to somehow define a syntax file for different kernels?

bug

Most helpful comment

Yep I should be able to sort that this week ๐Ÿคž

All 12 comments

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! :tada:

Hey @dsevero interesting, first I've ever heard of coconut!

According to the documentation, you should just need to have coconut installed in your document build environment: https://coconut.readthedocs.io/en/latest/DOCS.html#pygments

Does this work for you?

Hi, @chrisjsewell. Thank you for the response.

Coconut is great!

Yes, I have coconut installed.

As a second experiment, If I open a jupyter-notebook with coconut kernel the syntax works fine in the cells, but not when the book is built.

Is there anything else I can share to help?

What I'd plan to do next is first test that it works as advertised for "general" sphinx builds, e.g. running sphinx-quickstart, then adding to index.rst:

... code-block:: coconut

    range(10) |> map$(pow$(?, 2)) |> list

and see in if that builds correctly.

I'll get round to it some time soon, or feel free to try yourself ๐Ÿ˜„

or even quicker, you could also try adding this to your .md file and checking whether it highlights:

md ```{code-block} coconut range(10) |> map$(pow$(?, 2)) |> list ```

@chrisjsewell I added the following two:

` {code-cell} coconut
range(10) |> map$(pow$(?, 2)) |> list

match [head] + tail in [0, 1, 2, 3]:
print(head, tail)


```{code-block} coconut
range(10) |> map$(pow$(?, 2)) |> list

match [head] + tail in [0, 1, 2, 3]:
    print(head, tail)

````

Which resulted in
image

Hence the code-block works, but not the code-cell.

On the first run, I was missing cPyparsing==2.4.5.0.1.1 so I had to install it with pip. Not sure this is important, but I thought I might report it.

ok great thanks, so it appears an issue with myst-nb propagating the kernel language to the code-cells. I've added it to my TODO list!

I think that I have a similar issue. I'm using a Haskell kernel and a Scala kernel, and both languages are highlighted using the PythonLexer in the code cells.

Yep I should be able to sort that this week ๐Ÿคž

Ok fixed in myst-nb #234, and there's now a page in the documentation running Coconut ๐Ÿ˜„ https://myst-nb.readthedocs.io/en/latest/examples/coconut-lang.html
Should get this into jupyter-book in the next few days.

This should be closed in v0.8.0 ๐Ÿ˜„, but feel free to re-open/open another issue if anything is outstanding: https://jupyterbook.org/reference/_changelog.html#v0-8-0-2020-09-01

Excellent!
Miguel Montes

On Tue, Sep 1, 2020 at 12:24 PM Chris Sewell notifications@github.com
wrote:

This should be closed in v0.8.0 ๐Ÿ˜„, but feel free to re-open/open another
issue if anything is outstanding:
https://jupyterbook.org/reference/_changelog.html#v0-8-0-2020-09-01

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/executablebooks/jupyter-book/issues/878#issuecomment-684935822,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABWDL6LQ3OUJ6Z556NDVMXDSDUGZ7ANCNFSM4QADB5KQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akhmerov picture akhmerov  ยท  5Comments

rickwierenga picture rickwierenga  ยท  3Comments

utterances-bot picture utterances-bot  ยท  3Comments

bsamadi picture bsamadi  ยท  3Comments

mmcky picture mmcky  ยท  5Comments