🏠 back to Observable

python syntax highlighting

#1

I wonder why python

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

#2

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

0 Likes

#3

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.

0 Likes

#4

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

#5

Works perfectly. Thank you.

0 Likes

#6

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

#7

Works excellently.

0 Likes