Tables in pure Markdown

I really like this.
My idea is improvement for more machine- and human-readable.

Simple One Rule: Always start from a pipe character (|) for machine-readability.
This rule would avoid conflicts with other syntax.

|######################################## Caption Text ##########################################
|_______________________________________________________________________________________________,
|              | Header 1      || Header 2                     || Header 3                      |
|              | Subheader 1   | Subheader 2.1 | Subheader 2.2 |  Subheader 3.1 | Subheader 3.2 |
|==============|---------------|---------------|---------------|----------------|---------------|
| Row Header 1 ||| 3row, 3col span                             || Colspan only                  |
|______________|                                               |________________|_______________|
| Row Header 2 |^                                              |  Rowspan only  | Cell          |
|______________|                                               |                |_______________|
| Row Header 3 |^                                              |^               | Cell          |
|______________|_______________________________________________|________________|_______________|
| Row Header 4 | Row           | Each cell     |:   Centered  :| Right-aligned :|: Left-aligned |
|~             | with multiple | has room for  |   multi-line  |    multi-line  |  multi-line   |
|~             | lines.        | more text.    |      text.    |         text.  |  text.        |
|______________|_______________|_______________|_______________|________________|_______________/

For human-readability, rule lines are sometimes useful. For machines, however, these have no mean.
So lines starting from |_ can be introduced, which can be ignored like comment lines.

Let’s remove lines starting from |_.

|######################################## Caption Text ##########################################
|              | Header 1      || Header 2                     || Header 3                      |
|              | Subheader 1   | Subheader 2.1 | Subheader 2.2 |  Subheader 3.1 | Subheader 3.2 |
|==============|---------------|---------------|---------------|----------------|---------------|
| Row Header 1 ||| 3row, 3col span                             || Colspan only                  |
| Row Header 2 |^                                              |  Rowspan only  | Cell          |
| Row Header 3 |^                                              |^               | Cell          |
| Row Header 4 | Row           | Each cell     |:   Centered  :| Right-aligned :|: Left-aligned |
|~             | with multiple | has room for  |   multi-line  |    multi-line  |  multi-line   |
|~             | lines.        | more text.    |      text.    |         text.  |  text.        |

I think that it is better to use double or more pipe character BEFORE a table cell.
It makes parser a little easier for the colspan attribute creation.
Also, it allows us omit the last pipe character.

|######################################## Caption Text ##########################################
|              | Header 1      || Header 2                     || Header 3
|              | Subheader 1   | Subheader 2.1 | Subheader 2.2 |  Subheader 3.1 | Subheader 3.2
|==============|---------------|---------------|---------------|----------------|---------------
| Row Header 1 ||| 3row, 3col span                             || Colspan only
| Row Header 2 |^                                              |  Rowspan only  | Cell
| Row Header 3 |^                                              |^               | Cell
| Row Header 4 | Row           | Each cell     |:   Centered  :| Right-aligned :|: Left-aligned
|~             | with multiple | has room for  |   multi-line  |    multi-line  |  multi-line
|~             | lines.        | more text.    |      text.    |         text.  |  text.

Lines starting from |# constitute a caption text.
For this example, I write a caption text before a table because a <caption> element should be the first child of <table> element, but it’s not important.
Like lines for h1, h2, …, enclosing text with # should be allowed but its count does not matter.
The simplest form is |# Caption Text.

Keyword |^ increases rowspan, but no space should be allowed between | and ^ to simplify parser.
This no space rule would be also useful for other keywords.

To describe a row with multiple lines, keyword |~ can be used at the first of subsequent lines, instead of : use as a column separator.
Optionally |~ can be used not only at the first but also at each separator, but the first |~ is required.

Finally, I think that table syntax can be a extension of CommonMark, but I will be happy if it is released as a formal specification!

2 Likes