webuni/commonmark-table-extension

This package is abandoned and no longer maintained. The author suggests using the league/commonmark-ext-table package instead.

The table extension for CommonMark PHP implementation

Installs: 694 267

Dependents: 27

Suggesters: 0

Stars: 42

Watchers: 4

Forks: 18

Open Issues: 1

Type:commonmark-extension

1.0.0 2019-07-09 13:34 UTC

README

Latest Version Build Status Code Quality Code Coverage

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

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:

th | th(center) | th(right)
---|:----------:|----------:
td | td         | td

Result:

<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

| 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

header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[Simple table]

Code:

header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[*Prototype* table][reference_table]

Result:

<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>

Development

You need to have php or docker installed to develop the library. To list all available commands run:

./run