Some Bits: Nelson's log

Markdown processing in Python

I’m mad enough about Hugo I spent an hour writing a very minimal blog engine. Lots to go to make it usable, but as a piece of it I had to look for a Markdown processor for Python. Here’s what I’ve found, there are probably more. I want something that supports CommonMark and has a decent extension story. (A lot of folks support GitHub flavored markdown, perhaps that’s coherent enough to also be reasonable.)

mistletoe. 652 GitHub stars. I’ve used this already and it works but haven’t gotten in deep. Docs and PyPI niceties are not great. Says it’s the fastest implementation but all of these are pretty close (except Mistune which is way faster). Supports rendering to other targets like LaTeX, not just HTML.

markdown-it-py. 517 GitHub stars. Looks comprehensive, has a bunch of plugins. It’s a port from NodeJS code. Plugin code looks pretty complicated.

mdformat. 263 stars. Has plugins and code is connected somehow to markdown-it.

marko. 249 stars. Says it has very easy plugins and is not very fast but correct.

Mistune. 2300 stars. Not CommonMark but maybe reasonably so. Very fast. Plugins look awkward.

Not CommonMark: Markdown, Markdown2,

No real conclusion here. I’ll stick with mistletoe since I already have it working, then look to jump when I get to the part where I need my own plugins. marko or Mistune look most promising to me if mistletoe won’t work.

Update: some very simple evaluation

I did some quick tests comparing mistletoe, marko, markdown_it, and Mistune.

The output of all three were substantially similar. mistletoe emits actual ” ASCII quotes whereas the other two are outputing ". Which reminds me I need to enable typographic quotes.

Some very simple benchmarks show mistletoe and markdown_it takes 2-3x as long as mistune, marko is about 4x.
timeit 9000 byte input: mistune (1.13ms), markdown_it (2.78ms), mistletoe (3.60ms), marko (4.84ms)
1800 HTML posts: mistune (490ms), mistletoe (860ms), markdown_it (925ms), marko (2000ms)

Update 2: markdown_it

After reading docs and setting up typographical quotes I think I’ll go with markdown_it. I was turned off at first because it was a NodeJS port and its code seems quite complicated, they really want to explore details of parsers, ASTs, renderers to you. But it does typographical quotes right! And it’s fast and popular. Now that I’m over the learning hump it seems a good choice. I haven’t tried writing a plugin for it yet though.