Markdown vs reStructuredText for teaching materials

Featured image: Brandi Redd | Unsplash (photo)

Back in summer 2017. I wrote an article explaining why we used Sphinx and reStructuredText for producing teaching materials and not a wiki. In addition to recommending Sphinx as the solution to use, it was a general praise for generating static HTML files from Markdown or reStructuredText.

This summer I made the conversion of teaching materials from reStructuredText to Markdown. Unfortunately, the automated conversion using Pandoc didn’t quite produce the result I wanted so I ended up cooking my own Python script that converted the specific dialect of reStructuredText that was used for writing the contents of and fixing a myriad of inconsistencies in writing style that accumulated over the years.

reStructuredText as the obvious choice for the software documentation

I personally preferred to write reStructuredText, which I found to be more powerful and better standardized than Markdown (I have heard the same is true about AsciiDoc though I haven’t personally used it). When we forked rDock to start RxDock, reStructuredText and Sphinx were the obvious choice for its documentation. A good argumentation why would a software developer prefer reStructuredText over Markdown for software documentation is given in a very fine article written by Victor Zverovich. He mentions two main advantages, first one being:

reStructuredText provides standard extension mechanisms called directives and roles which make all the difference. For example, you can use the math role to write a mathematical equation (…) and it will be rendered nicely both in HTML using a Javascript library such as MathJax and in PDF via LaTeX or directly. With Markdown you’ll probably have to use MathJax and HTML to PDF conversion which is suboptimal or something like Pandoc to convert to another format first.

(For what it’s worth, this has now been addressed by PyMdown Extension Arithmatex, which is easy to enable when using MkDocs with Material theme.)

The second advantage mentioned by Zverovich is very useful for software documentation and a feature that would be only nice to have elsewhere:

In addition to this, Sphinx provides a set of roles and directives for different language constructs, for example, :py:class: for a Python class or :cpp:enum: for a C++ enum. This is very important because it adds semantics to otherwise purely presentational markup (…)

Markdown as the obvious choice elsewhere

Despite recommending reStructuredText for software documentation, Victor opens his blog post with:

In fact, I’m writing this blog post in Markdown.

It’s the obvious choice since GitHub Pages offers the Markdown to HTML conversion so you can worry about writing the contents, but the same feature isn’t available for reStructuredText and AsciiDoc. Unfortunately for rST, GitLab supports Markdown and AsciiDoc, but not reStructuredText (it has been requested 5 years ago). (However, GitLab Pages supports almost anything you can imagine thanks to GitLab CI/CD, including Sphinx.)

And it’s a similar story elsewhere. Reddit? Markdown. Slack and Mattermost? Both Markdown. Visual Studio Code supports Markdown without any extensions (but there are 795 of them available if you feel that something you require is not there, compared to 21 for reStructuredText) and it’s a very popular choice among my colleagues and students. Also, there is nothing like HackMD for reStructuredText or AsciiDoc that I know of.

Obviously, many of these tools weren’t around when we switched to Sphinx back in 2014. However, now that they are here to stay, Markdown is starting to look as a better choice among the two.

Moving from reStructuredText to Markdown for teaching materials

In my particular case, the straw that broke the camel’s back and made me decide to convert the teaching materials from reStructuredText to Markdown was the student contribution of ZeroMQ exercises for the Distributed systems course (not included yet). I asked the student to write reStructuredText, but got the materials in Markdown and I can understand why is that. Let’s say that student wanted to do things properly in reStructedText and Sphinx. The procedure is this:

  1. Git clone the repository.
  2. Open the folder in your favorite editor, say VS Code, notice it doesn’t highlight rST out of the box, no problem there is the extension, right?
  3. Install the reStructuredText extension (homepage), close all NotImplemented exception notes that appear when opening the project.
  4. Open a file just the get the feeling of how rST should look. Try to preview it. Unknown directive type “sectionauthor”. Never mind, it’s just one command that is unsupported.
  5. The code isn’t highlighted. Oh well, it’s not a show stopper.
  6. Well, the is more errors in preview. Never mind, the compile is the real preview. Let’s compile things every time something is changed.
  7. (…)
  8. Send the changes by e-mail or git add, git commit, and git push.

Compare that with the Markdown workflow:

  1. Git clone the repository.
  2. Open the folder in VS Code and start writing.
  3. Send the changes by e-mail or git add, git commit, and git push.

To be fair, VS Code Markdown preview is not rendering Admonitions, but that’s how it goes with the language extensions. Still, it’s much easier to get started with Markdown and MkDocs than with reStructuredText and Sphinx if you are new to documentation writing, which is the case with most of the students.

There are a number of other things I like:

  • Material theme for MkDocs is awesome. It’s a set of extensions in addition to a good looking theme.
  • Integrated search is designed as “find as you type” and provides a much better user experience.
  • Much faster building. It takes 11 seconds to build the group website with MkDocs, while it took 37 seconds to build the older version of the same website with Sphinx.
  • Builtin GitHub Pages deployment functionality. It’s possible to do the same with Sphinx, but it’s much nicer to have it builtin and maintained.
  • Automatic building of the sitemap. (There’s an extension for Sphinx that does the same.)

Overall, I am very satisfied with the results and I’m looking forward to using Markdown for writing teaching materials in the future. I’ll continue to write RxDock documentation in reStructuredText since fancy cross-references and numbered equation blocks are very easy to do in reStructuredText. In addition, there is the official way to produce PDF output via LaTeX, which is quite important to have for proper scientific software documentation. Also, the potential contributors in this case are somewhat experienced with documentation tools and can usually find their way around with reStructuredText and Sphinx so it’s not that much of an issue.