Skip to content

Generate html from markdown with code-block highlighting

License

Notifications You must be signed in to change notification settings

asottile/markdown-code-blocks

Folders and files

NameName
Last commit message
Last commit date
Jan 30, 2025
Jul 12, 2022
Mar 13, 2022
Feb 17, 2025
Mar 14, 2017
Dec 29, 2022
Oct 11, 2024
May 27, 2020
Oct 11, 2024
Jan 15, 2022
Jul 1, 2023

Repository files navigation

build status pre-commit.ci status

markdown-code-blocks

A stupid simple bit of code which combines mistune and pygments to convert markdown into html. Very similar to github markdown, but for python.

Installation

pip install markdown-code-blocks

Usage

The library provides a single function highlight which takes in a markdown string and returns html.

You can also use the cli markdown-code-blocks-highlight. It optionally takes a single filename (defaulting to stdin) and writes to stdout.

For example:

markdown-code-blocks-highlight f.md > f.htm

pygments css

I'd suggest grabbing a theme file from pygments-css (or any other provider of pygments themes -- if you google there's a bunch of them).

This library will use the class .highlight so be sure to change out whatever class the theme uses with that.

Most themes (for whatever reason) don't add styles for diff display. I usually do something like this:

.highlight .gi { color: #070; }
.highlight .gd { color: #911; }