blob: 05f7359ec8f3373d16adfdf14977fbd1fd0b4ced (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
CommonMark Table Extension
==========================
[](https://packagist.org/packages/webuni/commonmark-table-extension)
[](https://travis-ci.org/webuni/commonmark-table-extension)
[](https://scrutinizer-ci.com/g/webuni/commonmark-table-extension/code-structure)
[](https://scrutinizer-ci.com/g/webuni/commonmark-table-extension)
The Table extension adds the ability to create tables in CommonMark documents.
Installation
------------
This project can be installed via Composer:
composer require webuni/commonmark-table-extension
Usage
-----
```php
use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use Webuni\CommonMark\TableExtension\TableExtension;
$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new TableExtension());
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
echo $converter->convertToHtml('# Hello World!');
```
Syntax
------
### Simple
Code:
```markdown
th | th(center) | th(right)
---|:----------:|----------:
td | td | td
```
Result:
```html
<table>
<thead>
<tr>
<th style="text-align: left">th</th>
<th style="text-align: center">th(center)</th>
<th style="text-align: right">th(right<)/th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">td</td>
<td style="text-align: center">td</td>
<td style="text-align: right">td</td>
</tr>
</tbody>
</table>
```
### Advanced
```markdown
| header 1 | header 2 | header 2 |
| :------- | :------: | -------: |
| cell 1.1 | cell 1.2 | cell 1.3 |
| cell 2.1 | cell 2.2 | cell 2.3 |
```
### Table caption
```markdown
header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[Simple table]
```
Code:
```markdown
header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[*Prototype* table][reference_table]
```
Result:
```html
<table>
<caption id="reference_table"><em>Prototype</em> table</caption>
<thead>
<tr>
<th>header 1</th>
<th>header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>cell 1.1</td>
<td>cell 1.2</td>
</tr>
</tbody>
</table>
<table>
```
|