# Pygments rather than highlight.js for syntax highlighting

**URL:** https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544
**Category:** Feature
**Tags:** code
**Created:** [December 17, 2025, 10:56am UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544 "2025-12-17T10:56:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dbitouze](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dbitouze](https://meta.discourse.org/u/dbitouze)
#### Post date: [December 17, 2025, 10:56am UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544/1 "2025-12-17T10:56:35Z")

</div>

For syntax highlighting, Discourse relies on `highlight.js` but [`Pygments`](https://pygments.org/) looks richer. For instance, here is how looks a Python code:

```python
text = input('Type a number, and its factorial will be printed: ')
n = int(text)

if n < 0:
    raise ValueError('You must enter a non-negative integer')

factorial = 1
for i in range(2, n + 1):
    factorial *= i

print(factorial)

```

to be compared with [how it could look with Pygments](https://pygments.org/demo/?lexer=python&style=dracula&formatter=html&code=text+%253D+input('Type+a+number%252C+and+its+factorial+will+be+printed%253A+')%0An+%253D+int(text)%0A%0Aif+n+%3C+0%253A%0A++++raise+ValueError('You+must+enter+a+non-negative+integer')%0A%0Afactorial+%253D+1%0Afor+i+in+range(2%252C+n+%252B+1)%253A%0A++++factorial+*%253D+i%0A%0Aprint(factorial)):

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/f/a/0fa6202a1f7c575b04a60cfff43893211742b41d.png)

This is more prominent for a LaTeX code block (unfortunately, this language is not enabled on the present forum) but here is how it looks on our Discourse forum:

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/0/f/20fe29eec0b319ec717e08e3cf7ffa2b208362f3.png)

to be compared with [how it could look with Pygments](https://pygments.org/demo/?lexer=&style=dracula&formatter=html&code=%5Cdocumentclass%5Bfrench%5D%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%5Butf8%5D%7Binputenc%7D%0A%5Cusepackage%7Blmodern%7D%0A%5Cusepackage%5Ba4paper%5D%7Bgeometry%7D%0A%5Cusepackage%7Bbabel%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cend%7Bdocument%7D):

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/e/1/8e1aad22c6a97b89ee27fad2b7b27d347e4d038b.png)

or even better with a customized theme/lexer:

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/b/c/2bca95dad16a3ddb3e0747d2ce98dabfd7034c35.png)

Would it be possible to rely on [`Pygments`](https://pygments.org/) rather than on `highlight.js`?

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [December 17, 2025, 11:55am UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544/2 "2025-12-17T11:55:49Z")

</div>

The problem is, it’s a Python package and not a Javascript one 👀 . I wonder if it can be converted over 🤔 .

---

<div class="post-metadata">

### Author: ![dbitouze](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dbitouze](https://meta.discourse.org/u/dbitouze)
#### Post date: [December 17, 2025, 12:16pm UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544/3 "2025-12-17T12:16:15Z")

</div>

Ah, indeed, Pygments looks to be suitable for static html sites, not for applications such as Discourse.

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [December 17, 2025, 1:16pm UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544/4 "2025-12-17T13:16:56Z")

</div>

Maybe a different theme from highlight.js would improve the colors too?

You can try them at [Demo - highlight.js](https://highlightjs.org/demo) and there is a component to change it  
[Codeblock Theme Picker](https://meta.discourse.org/t/codeblock-theme-picker/146396)

---

<div class="post-metadata">

### Author: ![dbitouze](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dbitouze](https://meta.discourse.org/u/dbitouze)
#### Post date: [December 17, 2025, 1:59pm UTC](https://meta.discourse.org/t/pygments-rather-than-highlight-js-for-syntax-highlighting/391544/5 "2025-12-17T13:59:37Z")

</div>

Indeed, another theme could provide nicer colors but the problem remains: the `highlight.js` lexer is minimalist.
