Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,387 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
This plugin implements a type of ASCII-style tables inspired by GitHub-flavored Markdown, Pandoc's pipe tables and PHP Markdown Extra's simple tables. | ||
|
||
See its [Syntax](Syntax.md). | ||
|
||
### References | ||
|
||
* [GitHub-flavored Markdown](https://help.github.com/articles/organizing-information-with-tables/) | ||
* [Pandoc's pipe_tables extension](http://pandoc.org/MANUAL.html#extension-pipe_tables) | ||
* [PHP Markdown Extra](https://michelf.ca/projects/php-markdown/extra/#table) | ||
|
||
## Example | ||
|
||
```php | ||
$configurator = new s9e\TextFormatter\Configurator; | ||
$configurator->plugins->load('PipeTables'); | ||
|
||
// Get an instance of the parser and the renderer | ||
extract($configurator->finalize()); | ||
|
||
$text = 'a | b' . "\n" | ||
. '--|--' . "\n" | ||
. 'c | d'; | ||
$xml = $parser->parse($text); | ||
$html = $renderer->render($xml); | ||
|
||
echo $html; | ||
``` | ||
```html | ||
<table><thead><tr><th>a</th><th>b</th></tr></thead> | ||
<tbody><tr><td>c</td><td>d</td></tr></tbody></table> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
### Simple table | ||
|
||
``` | ||
| Header 1 | Header 2 | | ||
|----------|----------| | ||
| Cell 1 | Cell 2 | | ||
``` | ||
|
||
### Compact table | ||
|
||
The outer pipes and spaces around pipes are optional. | ||
|
||
``` | ||
Header 1|Header 2 | ||
-|- | ||
Cell 1|Cell 2 | ||
``` | ||
|
||
### Text alignment | ||
|
||
``` | ||
| Left | Center | Right | | ||
|:-----|:------:|------:| | ||
| x | x | x | | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* @package s9e\TextFormatter | ||
* @copyright Copyright (c) 2010-2016 The s9e Authors | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
*/ | ||
namespace s9e\TextFormatter\Plugins\PipeTables; | ||
|
||
use s9e\TextFormatter\Configurator\Items\AttributeFilters\ChoiceFilter; | ||
use s9e\TextFormatter\Plugins\ConfiguratorBase; | ||
|
||
class Configurator extends ConfiguratorBase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $quickMatch = '|'; | ||
|
||
/** | ||
* Create the tags used by this plugin | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$tags = [ | ||
'TABLE' => ['template' => '<table><xsl:apply-templates/></table>'], | ||
'TBODY' => ['template' => '<tbody><xsl:apply-templates/></tbody>'], | ||
'TD' => $this->generateCellTagConfig('td'), | ||
'TH' => $this->generateCellTagConfig('th'), | ||
'THEAD' => ['template' => '<thead><xsl:apply-templates/></thead>'], | ||
'TR' => ['template' => '<tr><xsl:apply-templates/></tr>'] | ||
]; | ||
foreach ($tags as $tagName => $tagConfig) | ||
{ | ||
if (!isset($this->configurator->tags[$tagName])) | ||
{ | ||
$this->configurator->tags->add($tagName, $tagConfig); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Generate the tag config for give cell element | ||
* | ||
* @param string $elName Element's name, either "td" or "th" | ||
* @return array Tag config | ||
*/ | ||
protected function generateCellTagConfig($elName) | ||
{ | ||
$alignFilter = new ChoiceFilter(['left', 'center', 'right', 'justify'], true); | ||
|
||
return [ | ||
'attributes' => [ | ||
'align' => [ | ||
'filterChain' => ['strtolower', $alignFilter], | ||
'required' => false | ||
] | ||
], | ||
'rules' => ['createParagraphs' => false], | ||
'template' => | ||
'<' . $elName . '> | ||
<xsl:if test="@align"> | ||
<xsl:attribute name="style">text-align:<xsl:value-of select="@align"/></xsl:attribute> | ||
</xsl:if> | ||
<xsl:apply-templates/> | ||
</' . $elName . '>' | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function asConfig() | ||
{ | ||
return [ | ||
'overwriteEscapes' => isset($this->configurator->Escaper), | ||
'overwriteMarkdown' => isset($this->configurator->Litedown) | ||
]; | ||
} | ||
} |
Oops, something went wrong.