# python syntax highlighting

**URL:** <https://talk.observablehq.com/t/python-syntax-highlighting/1830>\
**Category:** Help\
**Created:** [March 28, 2019, 5:31pm UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830 "2019-03-28T17:31:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrzejQ](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andrzejq/32/1592_2.png) [@andrzejQ](https://talk.observablehq.com/u/andrzejQ)\
**Post date:** [March 28, 2019, 5:31pm UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/1 "2019-03-28T17:31:50Z")

</div>

I wonder why python

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

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [March 28, 2019, 7:02pm UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/2 "2019-03-28T19:02:28Z")

</div>

Observable uses [a custom build](https://unpkg.com/@observablehq/highlight.js@1.1.1/) of [highlight.js](https://highlightjs.org/) 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](https://observablehq.com/@bryangingechen/commenton), which was around November).

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [March 29, 2019, 5:24am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/3 "2019-03-29T05:24:18Z")

</div>

A search of observable notebooks turns up

> **[Advanced syntax highlighting](https://observablehq.com/@lsei/advanced-syntax-highlighting)**
>
> An Observable notebook by Lucas.

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.

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [March 29, 2019, 6:10am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/4 "2019-03-29T06:10:24Z")

</div>

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]);

```

> **[Python highlighting](https://observablehq.com/d/92dd31dc9ac3bfcd)**
>
> An Observable notebook by Jacob Rus.

---

<div class="post-metadata">

**Author:** ![andrzejQ](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andrzejq/32/1592_2.png) [@andrzejQ](https://talk.observablehq.com/u/andrzejQ)\
**Post date:** [March 29, 2019, 7:27am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/5 "2019-03-29T07:27:59Z")

</div>

Works perfectly. Thank you.

---

<div class="post-metadata">

**Author:** ![tom](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tom/32/2262_2.png) [@tom](https://talk.observablehq.com/u/tom)\
**Post date:** [April 13, 2019, 12:13am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/6 "2019-04-13T00:13:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrzejQ](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andrzejq/32/1592_2.png) [@andrzejQ](https://talk.observablehq.com/u/andrzejQ)\
**Post date:** [April 13, 2019, 9:53am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/7 "2019-04-13T09:53:26Z")

</div>

Works excellently.

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [August 26, 2020, 1:30am UTC](https://talk.observablehq.com/t/python-syntax-highlighting/1830/8 "2020-08-26T01:30:16Z")

</div>

> [@tom](#):
>
> we just greatly expanded the range of languages that can be highlighted in ``` blocks in Markdown

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