I Prefer RST to Markdown (2024)

https://news.ycombinator.com/rss Hits: 8
Summary

July 31, 2024 Why I prefer rST to markdown I will never stop dying on this hill I just published a new version of Logic for Programmers! v0.2 has epub support, content on constraint solving and formal specification, and more! Get it here. This is my second book written with Sphinx, after the new Learn TLA+. Sphinx uses a peculiar markup called reStructured Text (rST), which has a steeper learning curve than markdown. I only switched to it after writing a couple of books in markdown and deciding I needed something better. So I want to talk about why rst was that something. Why rst is better The most important difference between rst and markdown is that markdown is a lightweight representation of html, while rst is a midweight representation of an abstract documentation tree. It's easiest to see this with a comparison. Here's how to make an image in markdown: Technically, you don't even need a parser for this. You just need a regex to transform it into <img alt="alttext" src="example.jpg"/>. Most modern markdown engines do parse this into an intermediate representation, but the essence of markdown is that it's a lightweight html notation. Now here's how to make an image in rst: .. image:: example.jpg :alt: alttext .. image:: defines the image "directive". When Sphinx reads it, it looks up the registered handler for the directive, finds ImageDirective, invokes ImageDirective.run, which returns an image_node, which is an object with an alt field containing "alttext". Once Sphinx's processed all nodes, it passes the whole doctree to the HTML Writer, which looks up the rendering function for image_node, which tells it to output an <image> tag. Whew that's a mouthful. And for all that implementation complexity, we get… an interface that has 3x the boilerplate as markdown. On the other hand, the markdown image is hardcoded as a special case in the parser, while the rst image is not. It was added in the exact same way as every other directive in rst: register a handler for t...

First seen: 2025-08-18 01:39

Last seen: 2025-08-18 10:40