Build a Docusaurus-like Site with FastAPI: Step 3 - Code Highlighting
dev.to·7h·
Discuss: DEV
Flag this post

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