|
1 |
| -# list-table |
| 1 | +# List tables for Pandoc |
2 | 2 |
|
3 |
| -reStructuredText has so-called [list tables], which are not |
4 |
| -only easy-to-write but also produce clean diffs since you |
5 |
| -don't need to re-align all the whitespace when one cell width |
6 |
| -changes. This filter lets you use RST-inspired list tables in |
7 |
| -markdown. Any div with the first class `list-table` is |
8 |
| -converted, for example the following Markdown: |
| 3 | +This is the documentation for `list-table.lua`, a Lua filter |
| 4 | +to bring [RST-style list tables] to Pandoc's Markdown. |
| 5 | + |
| 6 | +List tables are not only easy-to-write but also produce clean |
| 7 | +diffs since you don't need to re-align all the whitespace when |
| 8 | +one cell width changes. This filter lets you use RST-inspired |
| 9 | +list tables in markdown. Any div with the first class `list-table` |
| 10 | +is converted, for example the following Markdown: |
9 | 11 |
|
10 | 12 | ```
|
11 | 13 | :::list-table
|
12 |
| - * - Heading row 1, column 1 |
13 |
| - - Heading row 1, column 2 |
14 |
| - - Heading row 1, column 3 |
| 14 | + * - row 1, column 1 |
| 15 | + - row 1, column 2 |
| 16 | + - row 1, column 3 |
15 | 17 |
|
16 |
| - * - Row 1, column 1 |
| 18 | + * - row 2, column 1 |
17 | 19 | -
|
18 |
| - - Row 1, column 3 |
| 20 | + - row 2, column 3 |
19 | 21 |
|
20 |
| - * - Row 2, column 1 |
21 |
| - - Row 2, column 2 |
| 22 | + * - row 3, column 1 |
| 23 | + - row 3, column 2 |
22 | 24 | :::
|
23 | 25 | ```
|
24 | 26 |
|
25 | 27 | results in the following table:
|
26 | 28 |
|
27 |
| -| Heading row 1, column 1 | Heading row 1, column 2 | Heading row 1, column 3 | |
28 |
| -|-------------------------|-------------------------|-------------------------| |
29 |
| -| Row 1, column 1 | | Row 1, column 3 | |
30 |
| -| Row 2, column 1 | Row 2, column 2 | | |
| 29 | +| row 1, column 1 | row 1, column 2 | row 1, column 3 | |
| 30 | +|-----------------|-----------------|-----------------| |
| 31 | +| row 2, column 1 | | row 2, column 3 | |
| 32 | +| row 3, column 1 | row 3, column 2 | | |
| 33 | + |
| 34 | +The filter also supports more advanced features, |
| 35 | +as described in the following sections. |
| 36 | + |
| 37 | +[RST-style list tables]: https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table |
| 38 | + |
| 39 | +## Table captions |
| 40 | + |
| 41 | +If the div starts with a paragraph its content is used as the table caption. |
| 42 | +For example: |
| 43 | + |
| 44 | +```markdown |
| 45 | +:::list-table |
| 46 | + Markup languages |
| 47 | + |
| 48 | + * - Name |
| 49 | + - Initial release |
| 50 | + |
| 51 | + * - Markdown |
| 52 | + - 2004 |
| 53 | + |
| 54 | + * - reStructuredText |
| 55 | + - 2002 |
| 56 | +::: |
| 57 | +``` |
| 58 | + |
| 59 | +results in: |
31 | 60 |
|
32 |
| -Three additional features are supported: |
| 61 | +<!-- HTML because GFM does not support table captions --> |
| 62 | +<table> |
| 63 | +<caption>Markup languages</caption> |
| 64 | +<thead> |
| 65 | +<tr> |
| 66 | +<th>Name</th> |
| 67 | +<th>Initial release</th> |
| 68 | +</tr> |
| 69 | +</thead> |
| 70 | +<tbody> |
| 71 | +<tr> |
| 72 | +<td>Markdown</td> |
| 73 | +<td>2004</td> |
| 74 | +</tr> |
| 75 | +<tr> |
| 76 | +<td>reStructuredText</td> |
| 77 | +<td>2002</td> |
| 78 | +</tr> |
| 79 | +</tbody> |
| 80 | +</table> |
33 | 81 |
|
34 |
| -* If the div starts with a paragraph its content is used as the table caption. |
| 82 | +## Column alignments |
35 | 83 |
|
36 |
| -* With the `align` attribute you can configure column alignment. When given |
37 |
| - the value must specify an alignment character (`d`, `l`, `r`, or `c` for |
38 |
| - default, left, right or center respectively) for each column. The characters |
39 |
| - must be separated by commas. |
| 84 | +With the `align` attribute you can configure column alignment. When given the |
| 85 | +value must specify an alignment character (`d`, `l`, `r`, or `c` for default, |
| 86 | +left, right or center respectively) for each column. The characters must be |
| 87 | +separated by commas. |
40 | 88 |
|
41 |
| -* With the `widths` attribute you can configure column widths via |
42 |
| - comma-separated numbers. The column widths will be relative to the numbers |
43 |
| - e.g. for `1,3` the second column will be three times as wide as the first. |
| 89 | +``` |
| 90 | +:::{.list-table align=l,c} |
| 91 | + * - Name |
| 92 | + - Initial release |
| 93 | +
|
| 94 | + * - Markdown |
| 95 | + - 2004 |
| 96 | +
|
| 97 | + * - reStructuredText |
| 98 | + - 2002 |
| 99 | +::: |
| 100 | +``` |
| 101 | + |
| 102 | +results in: |
| 103 | + |
| 104 | +| Name | Initial release | |
| 105 | +|:-----------------|:---------------:| |
| 106 | +| Markdown | 2004 | |
| 107 | +| reStructuredText | 2002 | |
| 108 | + |
| 109 | +## Column widths |
| 110 | + |
| 111 | +With the `widths` attribute you can configure column widths via |
| 112 | +comma-separated numbers. The column widths will be relative to the numbers. |
| 113 | +For example when we change the first line of the previous example to: |
| 114 | + |
| 115 | +``` |
| 116 | +:::{.list-table widths=1,3} |
| 117 | +``` |
44 | 118 |
|
45 |
| -For a demonstration of these features see [sample.md](sample.md). |
| 119 | +the second column will be three times as wide as the first column. |
46 | 120 |
|
47 |
| -[list tables]: https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table |
| 121 | +<!-- no demo because GFM does not support inline CSS --> |
0 commit comments