# Tables in pure Markdown

**URL:** <https://talk.commonmark.org/t/tables-in-pure-markdown/81>\
**Category:** Extensions\
**Created:** [September 3, 2014, 8:48pm UTC](https://talk.commonmark.org/t/tables-in-pure-markdown/81 "2014-09-03T20:48:29Z")\
**Posts on this page:** 1\
**Showing post:** 151

<div class="post-metadata">

**Author:** ![skystar0227](https://talk.commonmark.org/user_avatar/talk.commonmark.org/skystar0227/32/1673_2.png) [@skystar0227](https://talk.commonmark.org/u/skystar0227)\
**Post date:** [July 10, 2019, 7:39pm UTC](https://talk.commonmark.org/t/tables-in-pure-markdown/81/151 "2019-07-10T19:39:53Z")

</div>

> [@aoudad](#):
>
> A pipe table syntax with lots of features:
> 
> ```auto
> | | 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. :
> |--------------|-----------------|----------------|----------------|----------------|----------------|
> [Caption Text]
> 
> ```

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.

```auto
|######################################## 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 `|_`.

```auto
|######################################## 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.

```auto
|######################################## 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!

---

_[View the full topic](https://talk.commonmark.org/t/tables-in-pure-markdown/81)._
