Why I Prefer RST to Markdown
The author prefers reStructured Text (rST) over Markdown for technical documentation, citing its complex structure, custom directives, and better management of content across formats, despite its less attractive syntax.
Read original articleThe author discusses their preference for reStructured Text (rST) over Markdown, particularly in the context of writing technical documentation and books using Sphinx. They highlight that while Markdown is a lightweight representation of HTML, rST serves as a midweight representation of an abstract documentation tree, allowing for more complex and powerful document structures. The author notes that rST's directives enable the creation of custom text objects and facilitate transformations of the document tree before rendering, which is particularly useful for cross-referencing and managing content in different output formats like HTML, PDF, and EPUB.
An example provided is the author's book "Logic for Programmers," where they implemented a custom exercise extension to manage exercises and solutions effectively. This extension allows for inline rendering in HTML while organizing solutions differently in other formats. The author acknowledges that rST's syntax may be considered unattractive by some, but argues that its capabilities outweigh aesthetic concerns. They emphasize that many Markdown-based documentation generators often require workarounds to achieve similar functionality, which can limit their power. Ultimately, the author encourages readers to explore the potential of more robust documentation tools like rST, while recognizing that personal preferences for syntax may lead some to choose alternatives.
Related
The Eternal Truth of Markdown
Markdown, a simplified code alternative to HTML, enables diverse document formats from plain text. Despite lacking standardization, it thrives for its adaptability and simplicity, appealing to writers and programmers alike.
What TeX Gets Right
TeX, developed in the 1970s, remains a potent tool for technical writing, especially in mathematics and complex structures. Despite historical limitations, its reliability, efficiency, and community support are praised. Suggestions for modernization are implied.
- Many commenters appreciate Markdown for its simplicity and readability, making it accessible for non-technical users.
- Conversely, rST is praised for its extensibility and capabilities in handling complex documentation needs, particularly in professional settings.
- Several users express frustration with rST's syntax, finding it cumbersome compared to Markdown.
- There is a consensus that the choice between rST and Markdown often depends on the specific use case, with Markdown being favored for quick notes and rST for detailed documentation.
- Some commenters suggest alternatives like AsciiDoc or HTML, highlighting the diversity of tools available for documentation.
Yes. A thousand times yes. Because the biggest advantage of Markdown is that it's easy to read, and its second-biggest advantage is that it's easy to write. How easy it is to parse doesn't matter. How easy it is to extend is largely irrelevant.
Markdown may or may not be the best tool for writing a book, but Markdown is the best tool for what it does - quickly writing formatted text in a way that is easy to read even for those who are not well versed in its syntax.
I don't want to write a book. If I did I'd use LaTeX before RST. I want something to take notes, make quick documentation and thread comments.
reStructuredText (reST) by itself can be pretty rough. reST combined with Sphinx is pretty great. I.e. the strengths of Sphinx far outweigh the weaknesses of reST. For big, professional docs sites (+100 pages, +10 contributors) I have pretty strong opinions that Sphinx is probably the most responsible choice, long-term.
> 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.
Yes, what this means in practice is that it's easy to customize common aspects of your site (such as how images are displayed). A teammate of mine on Pigweed recently created a shortcut for linking to bugs consistently. You type :bug:`59385981` and the link gets transformed into https://pwbug.dev/59385981. If we ever need to mass-migrate all of our bug links, it's now trivial. Another profoundly important consequence of this architecture: all internal links are guaranteed to always resolve (you get warnings/errors if you link somewhere that doesn't exist). I previously wrote about how baffling it is that this is not the industry standard for docs sites: https://technicalwriting.dev/src/link-text-automation.html
The other thing that Sphinx excels at: well-defined extension and theme APIs. It's not exactly easy to build extensions or themes, but lots of people have figured it out (including me). There's a pretty rich ecosystem of extensions and themes on PyPI.
Lately I've been calling Sphinx the sleeping giant of docs systems. It's already pretty great and with a little concerted effort I think we can collectively make it absolutely phenomenal. The upstream Sphinx repo now has a GitHub Discussions section that gets a little traffic; a lot of us seem to congregrate on the #sphinx channel in the Write The Docs Slack.
This is my main problem with the article, as this is decidedly incorrect.
Markdown was designed as a tool of conversion of de facto standard of formatting text in email messages and Usenet posts of early nineties. The basic 7-bit ASCII nature of those technologies inspired people to informally annotate the text with special signs to denote formatting like emphasis, section titles and the like.
True, HTML shares a lot of similarities with that nameless standard, so John Gruber in 2004 wrote a basic script [0] to convert the latter to the former, never expecting it to become such a universally used actual standard.
To me, the whole point of markdown is to allow you to do simple things faster than writing raw HTML, but with the ability to intersperse raw HTML when needed.
In projects where I've needed the power of RST over markdown, I've felt more comfortable just writing raw HTML directly.
Two problems I had were: (1) common with a lot of systems, the RST tools don't contain an RST unparser. I really wanted to be able to generate RST files automatically by merging content from other RST files and other sources and working with them via a document API. The RST tools don't support that. (2) The RST tools expect a certain defined set of blocks for a particular document; it would be very possible for a system to represent blocks in a generic way which would make possible tools that can transform documents without necessarily knowing the definitions of blocks inside it.
These are problems w/ the tools, not problems with RST itself but every time I'm forced to strip my code back to the walls is an opportunity to think about some other markup system such as something HTML-based.
I've started using MyST for my more recent projects, which gives me the features I care about from reStructuredText - references and table of contents - but lets me use markdown syntax, which is easier for contributors.
For example, Markdown's and ReStructuredText's support for tables is cumbersome to say the least. AsciiDoc's table formatting is much easier to read, write, and maintain, and AsciiDoc tables are more robust, supporting headers, captions, custom dimensions for tables/rows, and complex formatting within tables.
Some other benefits include:
• A single, standardized format where Markdown and ReStructuredText do not (in other words, there are no "flavors" like you have in Markdown).
• Concise and readable syntax.
• A more gradual learning curve that ReStructuredText (probably due to its consistency and excellent documentation).
• Superior styling options for your output.
• A superior toolchain to the other two markup languages.
• A rich set of built-in documentation features, so you rarely have to rely on third-party plugins.
AsciiDoc was designed from the ground up for technical documentation, whereas the other two get shoehorned into that role.
Having worked extensively with all three, I can't recommend AsciiDoc highly enough.
GitHub’s own docs for project pages don’t work. Do I need a .nojekyl file, are gh-pages branches still required? Is there a config error in the repo or did changes just not prop? I guess I’ll try actions. Fast forward a few hours and this is getting unreasonable, haven’t looked at read the docs in a while, let’s see if that works. Ok it’s being weird and wants sphinx maybe, let’s get sphinx to work with markdown, ok cool. The build works but the page width is broken after deployment even though I can’t reproduce on my machine so it must be the ads injection on the community tier.
I know all this is working fine for lots of projects and have done it myself in the past. It works after it’s working. But it’s all so unbelievably fiddly. Bottom line, Markdown vs Rst isn’t even a choice/pain point on my radar, it’s more down to finding that good fit for medium sized docs projects / static hosting.
They've got extremely similar goals, and for the most basic text, both read and write like plain text too. And it was obviously a time when this thing simply became a thing everybody desired, so many "formats" appeared.
Why did MD win has — IMO — nothing to do with how it's "simpler" or "more readable" — they are largely interchangeable for anything that's easily represented with whitespaces in pure ASCII.
Or does someone claim that the following is unreadable gibberish that they need a parser for?
The best friends
================
``markdown`` and ``reST`` are two formats that *largely* aim to achieve the same goals:
* Be simple to read without any parser
* Be quick and simple to type out
I really, really don't see how the Markdown variant of the above is better in any way (note that I am not saying that reST is better either)? It's mostly the weirdness of history that has one prevail over the other, but both are good enough for their core goals.We had our documentation in asciidoc and it was awesome to write. We migrated to RTD/Sphinx/rST mainly for 1) better handling of i18n and 2) better handling of multiple-version-documentation (switching between versions)... and I loath rST every day. It's syntax is just abysmally awful and the tooling sucks (seriously, it's not just bad... it sucks!).
Nowadays there is antora but still - i18n is still a problem…
And markdown - as a simple tool to add some simple and basic formatting is just awesome and it's easily readable even if you don't have parser and end up having to read plaintext…
Asciidoc just seems to be much higher quality in general.
But at the same time, I find the writing experience for more advanced stuff too poor. The author talks about references, but do we have a language server that can look up available references, headlines, figure names etc and help you auto complete?
That’s what would make me take the plunge to a more advanced system.
![alttext](example.jpg)
RST: .. image:: example.jpg
:alt: alttext
The author prefers RST because: ... you can extend Sphinx with new text objects!
Say you that instead of an <image>, you want
a <figure> with a <figcaption> ...
What I would do: ![alttext](example.jpg)[caption]
And write a renderer which supports this syntax to create a figure with a figcaption. A markdown renderer is simple enough to write your own or extend an existing one.I guess this sort of falls under the "But I hate the syntax" section of the article, but I don't think it quite gets the point. I can look at a Markdown file and read or write it without even really thinking. Which is not really the case with rST (or even HTML, for that matter).
I'm reminded of all of the alternate worlds that didn't quite come to fruition, but could have (Lisp, Smalltalk, BeOS, etc.).
Whitespace has meaning, so I had to set up all sorts of indent highlights and dots for each space in my IDE to try to avoid screwing up the syntax inadvertently.
rst-lint and others exist, but don't seem to be maintained, and didn't seem to have documentation about how to add support for custom directives (which are definitely one of the key advantages of rST).
I'd write in rST again, but without an effective linter to stop me from making easy mistakes, I wouldn't be happy about it.
It turned out that no single markup language supported all of the features required to make physical books, so I would need custom tooling regardless. The rest of the world was moving onto MD, and even though I'm a huge Python fan, rST is painful, and writing tooling with it is even worse. (I also have commit rights for docutils.)
I don't regret my choice one bit. It has made my life much easier, and I can work much faster today.
Apart from the ugliness of the syntax from a devex perspective, I think one of the big advantages of Markdown is that it's highly readable even without being interpreted, which rST is not. So if you have a markdown document and no markdown interpreter, an average person can still make more or less perfect sense of the contents, including the hierarchy and emphasis.
> I think Restructured Text is better for writing books than Markdown.
That would be a better title.
I hugely prefer to write in RST, but as soon as I'm not alone we always switch to MD, given enough coworkers.
At some point (and Rst[1] has a tendency to look like this, but only a little) it can start to look like some alternative, less regular markup language. Maybe you just use more backticks rather than angle “brackets”. Or maybe you have (like previously stated) marshalled all the ascii symbols so that all the common stuff can have a terse representation.
Maybe they should just make a regular-looking markup for the unusual cases/user defined things. They could do something like Pollen with its Latex[1] syntax inspiration.
[1] Initial caps for proper nouns
I feel like "simple markdown" is a straw man here. If you're doing anything complex with markdown you're going to pick a flavor and learn it. Many flavors of markdown can do the things described.
Here's a Hugo figure which looks easier to understand than the "ugly rST" equivalent: https://gohugo.io/content-management/shortcodes/#embedded-sh...
What I came up with:
* Each page gets its own folder.
* An optional METADATA file in each folder has stuff like the type of the page (blog post, photo gallery, code listing).
* The index file can be in Markdown or rST or something. I'd just branch to a different parser based on the file name suffix.
This is simple and lets me evolve the blog over time.
For a personal blog, an ideal mix might be just branching to a different HTML converter based on the
I like my Markdown documents to be nicely readable in source form. Because that's what I'm editing so being readable helps, and it's also what I read most of the time.
I don't think Markdown is perfect. I have gripes. But it's "good enough", and damn near everywhere already so it's "in the fingers", so to speak.
> Markdown doesn't have a uniform extension syntax or native support for pre-render transforms.
Well no, but "Markdown" is also a standard with more implementations you can shake a stick at, whereas most of the alternates mentioned n the article are basically just a program written in $lang, and that's it. I think some do have a spec document, but also don't really have complete alternative implementations, so it doesn't really matter.
And I get the point; for my own website I have this ... piece of art ... to transform some of the HTML: https://github.com/arp242/arp242.net/blob/master/_plugins/ma...
On one hand: eww. On the other hand: it's not strictly needed, hard to do cross-platform, and has been working fine for a long time now. So whatever.
I have written a ton of documents in plain HTML, including slide decks, documentation for customers, reports for customers, a blog. I have not written a book yet. If I were to write a book, I would use LaTeX because then the typographic fidelity of the output would be my paramount objective.
Plain HTML is actually pretty awesome. It allows you to encode the structure of the document and then style if however you wanted. When I started in this business, you had to use LaTeX for that kind of flexibility. HTML has gotten a bad rep, I think, because it's dark side of including Javascript and a ton of frameworks for whatever perceived goal looks easy and seductive and then forces you into serfdom by obstructing future reuse.
If you stick with the bare minimum HTML you'll be fine. Better than fine actually. Text processors can these days usually import bare metal HTML just fine if need be. They only fail if you give them the "processed food" output of some kind of rendering pipeline.
The only other system for documentation we haven't covered in this thread is troff for man pages :-) Any takers?
I write a lot of markdown at work, and while you can't do this in commonmark, most parsers will absolutely let you define custom block types and transform the doctree and other things. You know how three backticks followed by the word 'python' produces syntax-highlighted code almost everywhere? You bet that I can do `::: warning` in my documentation to make the following content appear in a big red box with an exclamation mark.
As long as you don't put raw HTML in your source, you can even render to different targets like PDF. jupyter-book is a good example here.
Then there is Y axis of tools. 1. markdown and with it Z axis of mkdocs, hugo, KMSs like obsidian <name everything markdown here> 2. rst 3. org? 3. wysiswg editors or anything custom.
I find - markdown both ubiquitous and somewhat approachable. for most beginners. with obsidian/logseq/... it can also work for non tech writers too. its also more widely supported. [Github i am looking at you] - dev rel/dev tools docs with sphinx and rst is absolutely godsend! also a vibrant ecosystem. - product docs with mkdocs x markdown if its a consumer facing docs with lots of images and need for customizing. rst if its a developer product.
---
I write my blog in markdown, https://blog.shaishav.kr
My team maintained https://userdocs.rapyuta.io in markdown for the last 4 years. https://github.com/rapyuta-robotics/rapyuta-io-docs
- we also maintained https://sdk.rapyuta.io/ & https://cli.rapyuta.io/ both in semiautomated rst + github actions setup
rst:
.. image:: example.jpg
:alt: alttext
scroll: image example.jpg
caption alttext
"Directives" in rST are "Parsers" in Scroll. The item above would be parsed by the `imageParser`, which at ~50 lines of code (https://github.com/breck7/scroll/blob/b8fd72aa38742cc6cd575f...), is actually more code than the average parser.To write your "exercise extension" in Scroll, you would just need to write a few lines of code definining an "exerciseParser". You could put that in the same file you use it in, or in a file named "exercise.parsers".
I think you should explore Scroll -- https://scroll.pub/ -- might do everything you need in a simpler way!
But, I use markdown. Markdown is technically inferior, but it's just simpler and that's really what makes all the difference. There's things I can do in rst that are more logical, more powerful - and yet - I still use markdown and pictures.
To me, it's the usual problem that I like to illustrate with a config file:
while True:
1. You need a config. You make a text file and write values in it. It grows. Its unmanageable. It's terrible.
2. You write some proto to store the config. Its complex. It can do everything. It's relatively good but the more you use it, the more little problems show up. It looks like regedit, a sql database, a tree of trees, etc.
3. You throw it all away and write something with trade offs, that is reasonably simple, solve 80-90% of use cases and is otherwise somewhat limited. Sometimes, it feels like you might as well just use a text file.
What makes so many designers of these plain text formatting languages choose to not preserve newlines? I don't get it. Preserving newlines is one of the main features of plain text.
This causes the same annoying thing as hacker news comments do, like this intended multiline shopping list:
-eggs -flour -milk -sugar -salt
The iirc, syntax is :inline{property} and
::: block-directive {options}
contents
:::
It doesnt nest well, so I applied any document-level styles using the filename; but I'd imagine the yaml-style lead-in tags should be the correct way to do it. > Here's how to make an image in html:
I think you meant "markdown" instead of "html".And the author continues to explain how rST is convenient and flexible to a doc engine like Sphinx. This kind of argument confuses me as a user. That is, why would I care? I just want to write my doc fast with minimal effort, and couldn't give zero attention to how Sphinx works. Wouldn't an average user like me should just ask: what will rST offer that is 10X better than Markdown?
No, markdown is a set of standards around transforming a good looking text file into a rich format(this is usually html, but it does not have to be). The most important part about markdown is that it is a "good looking text file". If a markdown extension does not result in good looking text it has failed the one point of markdown. This is why markdown editors leave me confused, the whole point of markdown is to write a nice looking plain text document, if you are going to use a specialized editor why not use a better format?
Note that markdown is a terrible document format, with only vague presentational cues and no semantic ones. it starts to suck real quick. However, it is a great idea if you want a good looking plaintext document. People understandably keep trying to "fix" markdown with better semantic options but these by and large miss the point of markdown leaving a ugly document.
So RST may be the best thing since sliced bread, but it is not really in the same category as markdown, the plaintext for one is decidedly ugly.
OTOH, Markdown does not require newlines between list elements; which is more compact but limits the HTML that can be produced from the syntax.
MyST Markdown adds Sphinx roles and directives to Markdown.
nbsphinx adds docutils (RST) support back to Jupyter Notebooks. (IPython notebook originally supported RST and Markdown.)
Yeah, using markdown to write a book is very limiting and doesn't offer the control needed for typesetting.
OTOH, using markdown to write is liberating - you only get a few markup options, so you can focus on the content:
[It is] notable that the Feynman lectures (3 volumes) write about all of
physics in 1800 pages, using only 2 levels of hierarchical headings:
chapters and A-level heads in the text. It also uses the methodology of
sentences which then cumulate sequentially into paragraphs, rather than the
grunts of bullet points. Undergraduate Caltech physics is very complicated
material, but it didn’t require an elaborate hierarchy to organize.
Edward Tufte, forum post, ‘Book design: advice and examples’ thread
The result of running that tool is always API documentation, so you might need something for docs that aren’t structured that way.
Now, granted, I am clearly ok with fenced sections. And I love org-mode for most all things.
That's very annoying to write, and some people even add overlining. We're entering the ascii art domain here and I don't have time for that.
Markdown has already won over the technical users.
Enjoy your infinite support tickets caused by markdown. RST does nothing to help this.
Of course Markdown is simpler in many aspects. But therefore it lacks many things that rST has.
Jokes aside, org seems to have a more clear specification and is very easy so use. Why don't more people use it?
I think Github already renders README.org as good as README.md and READEM.rst.
Is this what the author means by markdown being lightweight, since the inverse isn't true except trivially?
You know what I don't like? HTML, for user submitted content in particular. The mess I've seen, after someone opted for using HTML for messages in a system, because that's what JS based editors were available for at the time. Endless need to work against XSS, with more and more incremental updates needed to the sanitization logic, some of which broke the presentation of the data in the DB.
Never again. Markdown, BBCode, anything but that.
As for docs? Currently just some Markdown, because that's what GitHub, GitLab, Gitea and others all know how to render.
Maybe something like https://www.mkdocs.org/ for the more standalone use cases.
I assume they’re talking about s-expressions? Then that’s a really bad example, because those are objectively beautiful.
Passion for most powerful tech can take you far, but not tohers in your team. For others, Markdown has a much lower barrier to entry and is easier to preview in your local editor
I wish there was a way to use it to render HTML and not just PDF.
I guess this is why he's not using Pollen, which is explicitly designed for this sort of thing, but based on Racket.
I actually settled on rST for writing fiction manuscripts, I think because I actually liked the syntax? Maybe I just needed proper header support. I'm compiling to DOCX via pandoc, so I'm not using the extensibility in the slightest. Anyway, it's amusingly validating to see someone else use it for a similar job.
I am utterly disappointed.
I want markdown for writing loose text in a way that will be shared with and edited by non-technical people. If something is not formatted such that it can be placed in-line, then we're entering the real of "function" abstractions, which non-technical people DESPISE WITH A PASSION. They won't say it, but I'm old, and wise enough to know it's a mistake.
In other words, Markdown is just an expanded BB Code for me. And it does its job very well, because BB Code was insufficient.
So that's the context in which I'm disappointed with rST here. Because it look like... A poor man's LaTeX. This stuff is way too complicated for Markdown's use case, and way less complex than the demands of a book. I don't want to take the use case of LaTeX and use a worse tool. Disappointment. That's all.
So, while I understand all the good parts, I am still kinda not convinced it's a better option looking at the final product.
I absolutely despise working with restructured text. Markdown I use allllll day long and it’s simple, fast, and a pleasure comparatively.
People like this just want to make the rest of us miserable.
.. image:: example.jpg
:alt: alttext
Great, I can close this article now.Never before on an article I've felt the vibes of the "I stopped reading there"-meme harder than here.
When the first link is also the second link, and both are to BUY a 15 dollar book with the default "pay anything price" bar set to 20, I am just clicking out and ignoring literally everything in your marketing post.
Others can discuss this RST thing I have never heard about, I am just here to point out you have now alienated one of your potential converts. Put the book link at the bottom, and dont double link to the same purchase page in the same paragraph. FFS.
For hobby usage, use whatever. But I would strongly oppose anyone who would try to make RST standard at my workplace.
A scrum-master, PO or marketing can write markdown. RST would be a hard sell.
Not really. Quoting https://en.wikipedia.org/wiki/Markdown
>Its key design goal was readability, that the language be readable as-is, without looking like it has been marked up with tags or formatting instructions, unlike text formatted with 'heavier' markup languages, such as RTF, HTML, or even wikitext
So, for use cases that don’t make a good match of this chief constraint, Markdown might not be the most relevant option. It’s just as meaningful as saying that we prefer TeX over Markdown because fine typographical tuning is an important concern of our specific usecase.
I admit I already dealt with a screw using a hammer, not having the right toolset at hand. But when the situation don’t call for adhoc heterodox actions, I prefer to match a screwdriver with a screw and a hammer with a nail.
Related
The Eternal Truth of Markdown
Markdown, a simplified code alternative to HTML, enables diverse document formats from plain text. Despite lacking standardization, it thrives for its adaptability and simplicity, appealing to writers and programmers alike.
What TeX Gets Right
TeX, developed in the 1970s, remains a potent tool for technical writing, especially in mathematics and complex structures. Despite historical limitations, its reliability, efficiency, and community support are praised. Suggestions for modernization are implied.