The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.
That’s from Gruber’s original Markdown spec, and is also quoted in the second paragraph of the CommonMark spec.
The approach I outline below has the overriding goal of readability/publishability as-is. It supports rich table functionality and is backwards compatible with GFM tables. It riffs off of the ideas of @jgm and others in this thread.
Start with the GFM tables extension. Then add the following:
Allow zero or multiple header rows. If there is no header, the header delimiter is optional (you may want to keep it for column alignment). Support column spans.
| heading 1 | heading 2 ||
| | sub head a | sub head b |
|-----------|--------------|---------------|
| aaa | bbb | cccc |
| spans two cols || cccc |
| aaa | bbb | cccc |
| spans three cols |||
| aaa | bbb | cccc |
Support row spans as well as long paragraphs and multiple block elements as cell content. Normally each text row is a table row, but the inclusion of a row delimiter signals that all rows in the table will be explicitly delimited. Notice that despite the complexity, it is easy to visually parse this as a 3 x 5 table:
| aaa | this is really long so I just | ccc |
| | continue down here | |
|.....|.................................|.....|
| aaa | bbb | ccc |
|.....|.................................|.....|
| this spans 2 (not 3) rows and 2 cols || ccc |
| ||.....|
| || ccc |
|.......................................|.....|
| aaa | bbb | ccc |
|.......................................|.....|
| aaa | - item one | ccc |
| | - item two | |
In addition to column-level default alignment specified in the header delimiter (per GFM), granular cell-level alignment can be specified in row delimiters.
|..........|:........:|..........|
| right | center | center |
|---------:|:---------|:--------:|
| right | left | center |
|..........|..........|..........|
| right | left | center |
|:........:|.........:|:.........|
| center | right | left |
|..........|..........|..........|
| right | left | center |
If row headers are important (for accessibility as @selfthinker says above), support identifying them in the header delimiter:
| | Small | Large |
|============|---------|--------|
| Salami | 8.99 | 10.99 |
| Hawaii | 9.49 | 11.49 |
| Margherita | 7.99 | 9.99 |
Optionally (if this is not too hard for parsers), column spans can be determined by pipe alignment. This is about as readable and as intuitive for writers as it gets:
| heading | heading 2 |
| | sub head a | sub head b |
|---------|----------------------|--------------|
| aaa | this is still just | ccc |
| | a single row but I | |
| | talk too much | |
|.........|......................|..............|
| aaa | bbb | ccc |
|.........|......................|..............|
| this spans two rows and two | ccc |
| columns |..............|
| | ccc |
|.........|......................|..............|
| aaa | bbb | ccc |
|.........|......................|..............|
| aaa | - item one | ccc |
| | - item two | |
Notice that the header clearly has two rows despite not having an explicit row delimiter because of the differing column spans of the two text rows. If this is too hard for parsers to see, we could require that an explicit row delimiter be used.