I agree that compatibility with the widely used pipe table syntax is a good idea. Here are some thoughts I wrote up a couple years ago, towards a spec for tables that is largely compatible with existing pipe tables but more flexible:
I tentatively agree with the current syntax’s decision that pipes |
create cell structure, and that literal pipes need to be escaped even inside code backticks. This is a departure from the general principle that nothing needs to be escaped inside code backticks, but it conforms to the general commonmark idea that block structure is discerned prior to inline structure.
Headers should be optional. So, this should be a table:
| a | b |
This too:
|:--:|--:|
| a | b |
I think |
should be required at the beginning and end of the row. I’d like to reserve this syntax for line blocks:
| 15 Main St.
| Chicago, IL
Note that existing pipe tables allow the leading and trailing pipe to be skipped. However, this makes it harder for parsers to tell right away whether we have a table line, and there’s also the issue flagged above about line blocks. Finally, especially if headers are not required, this increases the probability that a line with a literal |
will be wrongly treated as a table.
Alignments should be supported, in the now-standard way:
| right | left | center |
| ---: | :--- | :----: |
What to do if the rows have different numbers of columns? Presumably just add empty columns to all the rows. But there’s a question whether we should take the headers to determine the number of columns (and truncate body rows if needed) or just take the maximum number of cells in any row.
That would be the minimum.
I think colspans could be supported thus:
| this spans two columns || third column |
| this spans three columns |||
| aaa | bbb | cccc |
This means that if you want a blank cell you need space between the ||
s. This would be a departure from the way pipe tables currently work.
Maybe for rowspans:
| this spans two rows | bbb |
|^ | ccc |
These can be combined:
| this spans two rows and two colums|| bbb |
|^ || ccc |
| aaa | bbb | ccc |
One more thing that would be attractive in table syntax is a way to include long paragraphs in cells (or even multiple block elements).
For long paragraphs, one could do something like this:
| aaa | this is really long so I just |
! | continue down here |
| new | row here |
Here the exclamation marks say: add the contents of these cells to the cells above them. One could even have a list in a table cell using this syntax:
| aaa | - item one |
! | - item two |
| new | row here |
The !
is very similar to the |
, which has its good points and its bad points. Alternatively one could choose a different character with more contrast.
| aaa | - item one |
+ | - item two |
| new | row here |
Note that allowing long cell contents, and especially block level content inside cells, raises some issues about table layout. In HTML output this isn’t a problem, since browsers compute column widths that (usually) make sense for the content. But in other output formats, like latex, one must explicitly specify column widths. So one question is whether to have something in the syntax that represents relative column widths. Pandoc does this by using the lines of -
under the headers, but only in cases where the cells are too long to be represented without wrapping.
EDIT: fixed initial |
s in code blocks, which this forum converted to >
for some reason… @codinghorror - this seems to be a bug in discourse’s processing of posts received by HTML.