Using the Python Markdown library

For my blog , I use the Pypi package Markdown to convert Markdown files to HTML. All my text is stored as .md.

The library works well once the extensions are all setup. I use the extensions extra, meta, codehilite and markdown_checklist.extension. If you're used to Github markdown. These extensions will give you a similar setup.

The extension codehilite gives you syntax highlights compatible with Pygments.

To get the actual CSS-tags for the HTML, pygments includes a CLI tool for that:

pygmentize -S default -f html -a .codehilite

The -a .codehilite is necessary because of a class name used by codehilite.

I use meta data in the beginning of my Markdown files. For this I use the meta extension.

Snippet for how I use the library:

import markdown

md = markdown.Markdown(extensions=['extra', 'meta', 'codehilite', 'markdown_checklist.extension'])
doc = md.convert(text_md)
args = md.Meta()


Related posts: