Pygments rather than highlight.js for syntax highlighting

For syntax highlighting, Discourse relies on highlight.js but Pygments looks richer. For instance, here is how looks a Python code:

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:

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:

to be compared with how it could look with Pygments:

or even better with a customized theme/lexer:

Would it be possible to rely on Pygments rather than on highlight.js?

1 Like

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

3 Likes

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

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

You can try them at Demo - highlight.js and there is a component to change it
Codeblock Theme Picker

2 Likes

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