Create a table without a header in reStructuredText and Markdown
Have you ever written a table without a header in Markdown? It turns out that most Markdown parsers don't support tables without headers.
When I wrote the page about my book Control Your Home with Raspberry Pi on this website, I wanted to list some specifications (title, publication date, number of pages, ...) in a table without a header. In reStructuredText, which I'm using for this website, the code for the table looks like this:
+----------------------+-------------------------------------+ | **Title** | Control Your Home with Raspberry Pi | +----------------------+-------------------------------------+ | **Author** | Koen Vervloesem | +----------------------+-------------------------------------+ | **Publication date** | 2020-08-17 | +----------------------+-------------------------------------+ | **Number of pages** | 331 | +----------------------+-------------------------------------+ | **Price** | € 37.50 | +----------------------+-------------------------------------+ | **ISBN-13** | 978-1-907920-94-3 | +----------------------+-------------------------------------+ | **ISBN-10** | 1-907920-94-3 | +----------------------+-------------------------------------+ | **Publisher** | Elektor International Media (EIM) | +----------------------+-------------------------------------+
This is rendered by Nikola, the static site generator I'm using, as:
Title |
Control Your Home with Raspberry Pi |
Author |
Koen Vervloesem |
Publication date |
2020-08-17 |
Number of pages |
331 |
Price |
€ 37.50 |
ISBN-13 |
978-1-907920-94-3 |
ISBN-10 |
1-907920-94-3 |
Publisher |
Elektor International Media (EIM) |
This looks fine as a simple table without a header.
Now I wanted to do the same in Markdown in the corresponding GitHub repository with code examples. I could have written the README as a reStructuredText file, but I already created a README.md out of habit, so I tried to create the same table without header in Markdown. But apparently GitHub-flavoured Markdown and many other Markdown flavours don't support tables without headers.
That StackOverflow post linked above shows a hack that seems to work in many Markdown parsers, including in GitHub:
| <!-- --> | <!-- --> | |----------------------|-------------------------------------| | **Title** | Control Your Home with Raspberry Pi | | **Author** | Koen Vervloesem | | **Publication date** | 2020-08-17 | | **Number of pages** | 331 | | **Price** | € 37.50 | | **ISBN-13** | 978-1-907920-94-3 | | **ISBN-10** | 1-907920-94-3 | | **Publisher** | Elektor International Media (EIM) |
This adds HTML comment blocks in the header cells, which essentially adds an empty header row to the table. Unfortunately in GitHub the result looks a bit odd, with that compressed empty header row:
This is literally an ugly hack. Of course I can just create an HTML table without a header in the Markdown file, as shown in one of the StackOverflow answers, but that defeats the purpose of using a more human-centered markup language. So now I have converted the README file from Markdown to reStructuredText. The result is rendered by GitHub as:
Just like I wanted. It's these small quibbles with Markdown all the time that strenghten my preference for reStructuredText as a markup language.