In the previous article, we added support for dynamically rendering HTML from .md files.

But as you saw, the Python code block in docs/hello.md was rendered, but it looked plain and had no color highlighting, making it difficult to read.

In this article, we’ll solve this problem: using Pygments and python-markdown extensions to add syntax highlighting to our Markdown code blocks.

Step 1: Install Highlighting Dependencies

The python-markdown library supports extra features through “Extensions.” To implement code highlighting, we need the codehilite extension, which in turn depends on another library: Pygments.

Execute the following command to install Pygments:

pip ...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help