python syntax highlighting

I wonder why python

 is not highlighted…
https://observablehq.com/@andrzejq/brython-d3-html

Observable uses a custom build of highlight.js which only includes support for:

  • CSS,
  • JavaScript (aliases js, jsx),
  • JSON, and
  • XML (aliases: html, xhtml, rss, atom, xjb, xsd, xsl, plist)

(this was true last time I looked into this, which was around November).

A search of observable notebooks turns up

But there are also surely a bunch of javascript projects with syntax highlighting for python already built in that could be imported into a notebook.

Importing highlight.js

highlight = require('https://bundle.run/highlight.js@9.15.6')

then explicitly calling it seems to work.

code = html`<pre><code class=python> ...`
highlight.highlightBlock(code.children[0]);
1 Like

Works perfectly. Thank you.

An update from our side: we just greatly expanded the range of languages that can be highlighted in ``` blocks in Markdown. Languages are now loaded asynchronously when we need them, so everything from Haskell to SQL is now supported.

5 Likes

Works excellently.

Where should we go to report bugs in the syntax highlighting? (For example, when highlighting Matlab the .' operator for transposing a matrix is treated as the start of a string, and everything gets messed up thereafter.)

1 Like