Syntax highlighting using Pygments

Often, as coders, we want to be able to display code in a web page, and while it is a skill to read that code without syntax highlighting, a few colors can make the reading experience much more pleasant.

As is always the way with Python, there is a module already available that is able to do that for you, and of course it can be installed easily by the following command:

pip install Pygments

Note

Pygments only works with the known sections of code. So, if you want to display code snippets, we can do that. If, however, you want to highlight inline sections of the code, we either follow the next section on Markdown, or we need to use some online Javascript such as highlight.js.

To create code snippets, we need to ...

Get Learning Flask Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.