quarto-dev / quarto-dev/quarto-cli
Code block language not working with "allthekernels" kernel
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
Bug description
Still looking for a good solution to https://github.com/quarto-dev/quarto-cli/issues/135, I found https://github.com/minrk/allthekernels which seems like a great candidate: it's a simple Jupyter kernel that forwards code cells to different sub-kernels for different languages (this also seems to be the approach favored by the Jupyter developers, see https://github.com/jupyterlab/jupyterlab/issues/2815).
However I found some issues trying to use it with Quarto. Here's my test document a.qmd:
---
jupyter: atk
---
```{any}
>python3
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
2+2
```
```{any}
>octave
plot(magic(2))
2+2
```
First, two issues that should be fixed outside of Quarto I think:
-
Calling
quarto render a.qmdgivesERROR: TypeError: Cannot read properties of undefined (reading 'toLowerCase'). This is because thekernel.jsondoesn't define a language. The language key is required so this should probably be fixed in allthekernels. I fixed it by adding"language": "any"in thekernel.json. -
With the above fix, calling
quarto render a.qmdsometimes produces an HTML file with code cells but empty outputs. It looks like a latency issue: it normally works the second time (once the daemon is running). The same issue can be observed when running the cells in Jupyter Notebook so it's probably a problem in allthekernels.
Now the issue that should be fixed in Quarto I think: The execution requires that I mark code blocks with {any} to match the language declared in kernel.json. Due to this the code blocks are not formatted properly: no syntax highlighting and not even a gray background. What I would expect instead is to write
```{octave}
>octave
plot(magic(2))
2+2
```
and have it work as long as I have defined jupyter: atk. If this worked I could also write a Lua filter to infer the >octave line from the block language and insert it automatically.
Note: the same issue affects the SoS kernel (another polyglot kernel that additionally enables data exchange between the sub-kernels).
Tested with quarto 1.2.269 and 1.3.26 on Pop!_OS 22.04.
Checklist
- Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- Please format your issue so it is easier for us to read the bug report.
- Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- Please document the operating system you're running. If on Linux, please provide the specific distribution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible a.qmd example and run quarto render a.qmd using the atk Jupyter kernel. Trace how Quarto handles the kernel language and fenced block language, then verify that {octave} blocks execute while retaining syntax highlighting and the normal code-block background.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jupyter
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100