-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #787 from thephpleague/decorate-table-output
Decorate table output
- Loading branch information
Showing
10 changed files
with
197 additions
and
56 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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the league/commonmark package. | ||
* | ||
* (c) Colin O'Dell <colinodell@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\CommonMark\Renderer; | ||
|
||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Util\HtmlElement; | ||
|
||
final class HtmlDecorator implements NodeRendererInterface | ||
{ | ||
private NodeRendererInterface $inner; | ||
private string $tag; | ||
/** @var array<string, string|string[]|bool> */ | ||
private array $attributes; | ||
private bool $selfClosing; | ||
|
||
/** | ||
* @param array<string, string|string[]|bool> $attributes | ||
*/ | ||
public function __construct(NodeRendererInterface $inner, string $tag, array $attributes = [], bool $selfClosing = false) | ||
{ | ||
$this->inner = $inner; | ||
$this->tag = $tag; | ||
$this->attributes = $attributes; | ||
$this->selfClosing = $selfClosing; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Node $node, ChildNodeRendererInterface $childRenderer) | ||
{ | ||
return new HtmlElement($this->tag, $this->attributes, $this->inner->render($node, $childRenderer), $this->selfClosing); | ||
} | ||
} |
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,18 @@ | ||
<div class="table-responsive"><table> | ||
<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> | ||
<tr> | ||
<td>cell 2.1</td> | ||
<td>cell 2.2</td> | ||
</tr> | ||
</tbody> | ||
</table></div> |
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,11 @@ | ||
--- | ||
table: | ||
wrap: | ||
enabled: true | ||
attributes: { class: "table-responsive" } | ||
--- | ||
|
||
header 1 | header 2 | ||
-------- | -------- | ||
cell 1.1 | cell 1.2 | ||
cell 2.1 | cell 2.2 |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the league/commonmark package. | ||
* | ||
* (c) Colin O'Dell <colinodell@gmail.com> | ||
* | ||
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) | ||
* - (c) John MacFarlane | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\CommonMark\Tests\Unit\Renderer\Block; | ||
|
||
use League\CommonMark\Node\Node; | ||
use League\CommonMark\Renderer\ChildNodeRendererInterface; | ||
use League\CommonMark\Renderer\HtmlDecorator; | ||
use League\CommonMark\Renderer\NodeRendererInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HtmlDecoratorTest extends TestCase | ||
{ | ||
public function testRender(): void | ||
{ | ||
$inner = $this->getMockForAbstractClass(NodeRendererInterface::class); | ||
$inner->method('render')->willReturn('INNER CONTENTS'); | ||
|
||
$decorator = new HtmlDecorator($inner, 'div', ['class' => 'foo', 'id' => 'bar'], true); | ||
|
||
$this->assertSame('<div class="foo" id="bar">INNER CONTENTS</div>', (string) $decorator->render( | ||
$this->getMockForAbstractClass(Node::class), | ||
$this->getMockForAbstractClass(ChildNodeRendererInterface::class) | ||
)); | ||
} | ||
} |