## Tables (extension)
GFM enables the `table` extension, where an additional leaf block type is
available.
A [table](@) is an arrangement of data with rows and columns, consisting of a
single header row, a [delimiter row] separating the header from the data, and
zero or more data rows.
Each row consists of cells containing arbitrary text, in which [inlines] are
parsed, separated by pipes (`|`). A leading and trailing pipe is also
recommended for clarity of reading, and if there's otherwise parsing ambiguity.
Spaces between pipes and cell content are trimmed. Block-level elements cannot
be inserted in a table.
The [delimiter row](@) consists of cells whose only content are hyphens (`-`),
and optionally, a leading or trailing colon (`:`), or both, to indicate left,
right, or center alignment respectively.
```````````````````````````````` example
| foo | bar |
| --- | --- |
| baz | bim |
.
<table>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>baz</td>
<td>bim</td>
</tr>
</tbody>
</table>
````````````````````````````````
Cells in one column don't need to match length, though it's easier to read if
they are. Likewise, use of leading and trailing pipes may be inconsistent:
```````````````````````````````` example
| abc | defghi |
:-: | -----------:
bar | baz
.
<table>
<thead>
<tr>
<th style="text-align: center;">abc</th>
<th style="text-align: right;">defghi</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">bar</td>
<td style="text-align: right;">baz</td>
</tr>
</tbody>
</table>
````````````````````````````````
Include a pipe in a cell's content by escaping it, including inside other
inline spans:
```````````````````````````````` example
| f\|oo |
| ------ |
| b `\|` az |
| b **\|** im |
.
<table>
<thead>
<tr>
<th>f|oo</th>
</tr>
</thead>
<tbody>
<tr>
<td>b <code>|</code> az</td>
</tr>
<tr>
<td>b <strong>|</strong> im</td>
</tr>
</tbody>
</table>
````````````````````````````````
The table is broken at the first line not containing an
unescaped `|`:
```````````````````````````````` example
| abc | def |
| --- | --- |
| bar | baz |
> bar
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
<blockquote>
<p>bar</p>
</blockquote>
````````````````````````````````
```````````````````````````````` example
| abc | def |
| --- | --- |
| bar | baz |
bar
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
<p>bar</p>
````````````````````````````````
```````````````````````````````` example
| abc | def |
| --- | --- |
| bar | baz |
bar
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
<p>bar</p>
````````````````````````````````
The header row must match the [delimiter row] in the number of cells. If not,
a table will not be recognized:
```````````````````````````````` example
| abc | def |
| --- |
| bar |
.
<p>| abc | def |
| --- |
| bar |</p>
````````````````````````````````
The remainder of the table's rows may vary in the number of cells. If there
are a number of cells fewer than the number of cells in the header row, empty
cells are inserted. If there are greater, the excess is ignored:
```````````````````````````````` example
| abc | def |
| --- | --- |
| bar |
| bar | baz | boo |
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td></td>
</tr>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
````````````````````````````````
If there are no rows in the body, no `<tbody>` is generated in HTML output:
```````````````````````````````` example
| abc | def |
| --- | --- |
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
</table>
````````````````````````````````
Here are some non-tables:
```````````````````````````````` example
| Not enough table | to be considered table |
| Not enough table | to be considered table |
| Not enough table | to be considered table |
| ---- | --- |
.
<p>| Not enough table | to be considered table |</p>
<p>| Not enough table | to be considered table |
| Not enough table | to be considered table |</p>
<p>| ---- | --- |</p>
````````````````````````````````
A table may be indented up to three spaces:
```````````````````````````````` example
a | b | c
- | - | -
.
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
</table>
````````````````````````````````
```````````````````````````````` example
a | b | c
- | - | -
.
<pre><code>a | b | c
- | - | -
</code></pre>
````````````````````````````````
Pipe tables have exactly one header row, and do not interrupt paragraphs.
```````````````````````````````` example
| Too much table | to be considered table |
| Too much table | to be considered table |
|----------------|------------------------|
| Too much table | to be considered table |
.
<p>| Too much table | to be considered table |
| Too much table | to be considered table |
|----------------|------------------------|
| Too much table | to be considered table |</p>
````````````````````````````````
Other block structures, like headers, have higher priority than tables.
Tables can be nested in other elements, but don't benefit from laziness.
```````````````````````````````` example
# abc | def
------|-----
> abc | def
> ----|-----
> abc | def
----|-----
.
<h1>abc | def</h1>
<p>------|-----</p>
<blockquote>
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
</table>
</blockquote>
<blockquote>
<p>abc | def
----|-----</p>
</blockquote>
````````````````````````````````