Primo Committ
This commit is contained in:
69
vendor/league/commonmark/src/Extension/Table/Table.php
vendored
Normal file
69
vendor/league/commonmark/src/Extension/Table/Table.php
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\AbstractStringContainerBlock;
|
||||
use League\CommonMark\Block\Element\InlineContainerInterface;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class Table extends AbstractStringContainerBlock implements InlineContainerInterface
|
||||
{
|
||||
/** @var TableSection */
|
||||
private $head;
|
||||
/** @var TableSection */
|
||||
private $body;
|
||||
/** @var \Closure */
|
||||
private $parser;
|
||||
|
||||
public function __construct(\Closure $parser)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->appendChild($this->head = new TableSection(TableSection::TYPE_HEAD));
|
||||
$this->appendChild($this->body = new TableSection(TableSection::TYPE_BODY));
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return $block instanceof TableSection;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getHead(): TableSection
|
||||
{
|
||||
return $this->head;
|
||||
}
|
||||
|
||||
public function getBody(): TableSection
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return call_user_func($this->parser, $cursor, $this);
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor): void
|
||||
{
|
||||
}
|
||||
}
|
||||
66
vendor/league/commonmark/src/Extension/Table/TableCell.php
vendored
Normal file
66
vendor/league/commonmark/src/Extension/Table/TableCell.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\AbstractStringContainerBlock;
|
||||
use League\CommonMark\Block\Element\InlineContainerInterface;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class TableCell extends AbstractStringContainerBlock implements InlineContainerInterface
|
||||
{
|
||||
const TYPE_HEAD = 'th';
|
||||
const TYPE_BODY = 'td';
|
||||
|
||||
const ALIGN_LEFT = 'left';
|
||||
const ALIGN_RIGHT = 'right';
|
||||
const ALIGN_CENTER = 'center';
|
||||
|
||||
/** @var string */
|
||||
public $type = self::TYPE_BODY;
|
||||
|
||||
/** @var string|null */
|
||||
public $align;
|
||||
|
||||
public function __construct(string $string = '', string $type = self::TYPE_BODY, string $align = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->finalStringContents = $string;
|
||||
$this->addLine($string);
|
||||
$this->type = $type;
|
||||
$this->align = $align;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor): void
|
||||
{
|
||||
}
|
||||
}
|
||||
39
vendor/league/commonmark/src/Extension/Table/TableCellRenderer.php
vendored
Normal file
39
vendor/league/commonmark/src/Extension/Table/TableCellRenderer.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class TableCellRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!$block instanceof TableCell) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
if ($block->align !== null) {
|
||||
$attrs['align'] = $block->align;
|
||||
}
|
||||
|
||||
return new HtmlElement($block->type, $attrs, $htmlRenderer->renderInlines($block->children()));
|
||||
}
|
||||
}
|
||||
34
vendor/league/commonmark/src/Extension/Table/TableExtension.php
vendored
Normal file
34
vendor/league/commonmark/src/Extension/Table/TableExtension.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\ConfigurableEnvironmentInterface;
|
||||
use League\CommonMark\Extension\ExtensionInterface;
|
||||
|
||||
final class TableExtension implements ExtensionInterface
|
||||
{
|
||||
public function register(ConfigurableEnvironmentInterface $environment): void
|
||||
{
|
||||
$environment
|
||||
->addBlockParser(new TableParser())
|
||||
|
||||
->addBlockRenderer(Table::class, new TableRenderer())
|
||||
->addBlockRenderer(TableSection::class, new TableSectionRenderer())
|
||||
->addBlockRenderer(TableRow::class, new TableRowRenderer())
|
||||
->addBlockRenderer(TableCell::class, new TableCellRenderer())
|
||||
;
|
||||
}
|
||||
}
|
||||
284
vendor/league/commonmark/src/Extension/Table/TableParser.php
vendored
Normal file
284
vendor/league/commonmark/src/Extension/Table/TableParser.php
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\Document;
|
||||
use League\CommonMark\Block\Element\Paragraph;
|
||||
use League\CommonMark\Block\Parser\BlockParserInterface;
|
||||
use League\CommonMark\Context;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\EnvironmentAwareInterface;
|
||||
use League\CommonMark\EnvironmentInterface;
|
||||
|
||||
final class TableParser implements BlockParserInterface, EnvironmentAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var EnvironmentInterface
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
public function parse(ContextInterface $context, Cursor $cursor): bool
|
||||
{
|
||||
$container = $context->getContainer();
|
||||
if (!$container instanceof Paragraph) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lines = $container->getStrings();
|
||||
if (count($lines) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lastLine = \array_pop($lines);
|
||||
if (\strpos($lastLine, '|') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$oldState = $cursor->saveState();
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
$columns = $this->parseColumns($cursor);
|
||||
|
||||
if (empty($columns)) {
|
||||
$cursor->restoreState($oldState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$head = $this->parseRow(trim((string) $lastLine), $columns, TableCell::TYPE_HEAD);
|
||||
if (null === $head) {
|
||||
$cursor->restoreState($oldState);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$table = new Table(function (Cursor $cursor, Table $table) use ($columns): bool {
|
||||
// The next line cannot be a new block start
|
||||
// This is a bit inefficient, but it's the only feasible way to check
|
||||
// given the current v1 API.
|
||||
if (self::isANewBlock($this->environment, $cursor->getLine())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = $this->parseRow(\trim($cursor->getLine()), $columns);
|
||||
if (null === $row) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$table->getBody()->appendChild($row);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$table->getHead()->appendChild($head);
|
||||
|
||||
if (count($lines) >= 1) {
|
||||
$paragraph = new Paragraph();
|
||||
foreach ($lines as $line) {
|
||||
$paragraph->addLine($line);
|
||||
}
|
||||
|
||||
$context->replaceContainerBlock($paragraph);
|
||||
$context->addBlock($table);
|
||||
} else {
|
||||
$context->replaceContainerBlock($table);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
* @param array<int, string> $columns
|
||||
* @param string $type
|
||||
*
|
||||
* @return TableRow|null
|
||||
*/
|
||||
private function parseRow(string $line, array $columns, string $type = TableCell::TYPE_BODY): ?TableRow
|
||||
{
|
||||
$cells = $this->split(new Cursor(\trim($line)));
|
||||
|
||||
if (empty($cells)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The header row must match the delimiter row in the number of cells
|
||||
if ($type === TableCell::TYPE_HEAD && \count($cells) !== \count($columns)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$row = new TableRow();
|
||||
foreach ($cells as $i => $cell) {
|
||||
if (!array_key_exists($i, $columns)) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
$row->appendChild(new TableCell(trim($cell), $type, $columns[$i]));
|
||||
}
|
||||
|
||||
for ($j = count($columns) - 1; $j > $i; --$j) {
|
||||
$row->appendChild(new TableCell('', $type, null));
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function split(Cursor $cursor): array
|
||||
{
|
||||
if ($cursor->getCharacter() === '|') {
|
||||
$cursor->advanceBy(1);
|
||||
}
|
||||
|
||||
$cells = [];
|
||||
$sb = '';
|
||||
|
||||
while (!$cursor->isAtEnd()) {
|
||||
switch ($c = $cursor->getCharacter()) {
|
||||
case '\\':
|
||||
if ($cursor->peek() === '|') {
|
||||
// Pipe is special for table parsing. An escaped pipe doesn't result in a new cell, but is
|
||||
// passed down to inline parsing as an unescaped pipe. Note that that applies even for the `\|`
|
||||
// in an input like `\\|` - in other words, table parsing doesn't support escaping backslashes.
|
||||
$sb .= '|';
|
||||
$cursor->advanceBy(1);
|
||||
} else {
|
||||
// Preserve backslash before other characters or at end of line.
|
||||
$sb .= '\\';
|
||||
}
|
||||
break;
|
||||
case '|':
|
||||
$cells[] = $sb;
|
||||
$sb = '';
|
||||
break;
|
||||
default:
|
||||
$sb .= $c;
|
||||
}
|
||||
$cursor->advanceBy(1);
|
||||
}
|
||||
|
||||
if ($sb !== '') {
|
||||
$cells[] = $sb;
|
||||
}
|
||||
|
||||
return $cells;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cursor $cursor
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function parseColumns(Cursor $cursor): array
|
||||
{
|
||||
$columns = [];
|
||||
$pipes = 0;
|
||||
$valid = false;
|
||||
|
||||
while (!$cursor->isAtEnd()) {
|
||||
switch ($c = $cursor->getCharacter()) {
|
||||
case '|':
|
||||
$cursor->advanceBy(1);
|
||||
$pipes++;
|
||||
if ($pipes > 1) {
|
||||
// More than one adjacent pipe not allowed
|
||||
return [];
|
||||
}
|
||||
|
||||
// Need at least one pipe, even for a one-column table
|
||||
$valid = true;
|
||||
break;
|
||||
case '-':
|
||||
case ':':
|
||||
if ($pipes === 0 && !empty($columns)) {
|
||||
// Need a pipe after the first column (first column doesn't need to start with one)
|
||||
return [];
|
||||
}
|
||||
$left = false;
|
||||
$right = false;
|
||||
if ($c === ':') {
|
||||
$left = true;
|
||||
$cursor->advanceBy(1);
|
||||
}
|
||||
if ($cursor->match('/^-+/') === null) {
|
||||
// Need at least one dash
|
||||
return [];
|
||||
}
|
||||
if ($cursor->getCharacter() === ':') {
|
||||
$right = true;
|
||||
$cursor->advanceBy(1);
|
||||
}
|
||||
$columns[] = $this->getAlignment($left, $right);
|
||||
// Next, need another pipe
|
||||
$pipes = 0;
|
||||
break;
|
||||
case ' ':
|
||||
case "\t":
|
||||
// White space is allowed between pipes and columns
|
||||
$cursor->advanceToNextNonSpaceOrTab();
|
||||
break;
|
||||
default:
|
||||
// Any other character is invalid
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
private static function getAlignment(bool $left, bool $right): ?string
|
||||
{
|
||||
if ($left && $right) {
|
||||
return TableCell::ALIGN_CENTER;
|
||||
} elseif ($left) {
|
||||
return TableCell::ALIGN_LEFT;
|
||||
} elseif ($right) {
|
||||
return TableCell::ALIGN_RIGHT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setEnvironment(EnvironmentInterface $environment)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
private static function isANewBlock(EnvironmentInterface $environment, string $line): bool
|
||||
{
|
||||
$context = new Context(new Document(), $environment);
|
||||
$context->setNextLine($line);
|
||||
$cursor = new Cursor($line);
|
||||
|
||||
/** @var BlockParserInterface $parser */
|
||||
foreach ($environment->getBlockParsers() as $parser) {
|
||||
if ($parser->parse($context, $cursor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
39
vendor/league/commonmark/src/Extension/Table/TableRenderer.php
vendored
Normal file
39
vendor/league/commonmark/src/Extension/Table/TableRenderer.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class TableRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!$block instanceof Table) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$separator = $htmlRenderer->getOption('inner_separator', "\n");
|
||||
|
||||
$children = $htmlRenderer->renderBlocks($block->children());
|
||||
|
||||
return new HtmlElement('table', $attrs, $separator . \trim($children) . $separator);
|
||||
}
|
||||
}
|
||||
48
vendor/league/commonmark/src/Extension/Table/TableRow.php
vendored
Normal file
48
vendor/league/commonmark/src/Extension/Table/TableRow.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Cursor;
|
||||
use League\CommonMark\Node\Node;
|
||||
|
||||
final class TableRow extends AbstractBlock
|
||||
{
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return $block instanceof TableCell;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AbstractBlock[]
|
||||
*/
|
||||
public function children(): iterable
|
||||
{
|
||||
return array_filter((array) parent::children(), static function (Node $child): bool {
|
||||
return $child instanceof AbstractBlock;
|
||||
});
|
||||
}
|
||||
}
|
||||
37
vendor/league/commonmark/src/Extension/Table/TableRowRenderer.php
vendored
Normal file
37
vendor/league/commonmark/src/Extension/Table/TableRowRenderer.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class TableRowRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!$block instanceof TableRow) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$separator = $htmlRenderer->getOption('inner_separator', "\n");
|
||||
|
||||
return new HtmlElement('tr', $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator);
|
||||
}
|
||||
}
|
||||
66
vendor/league/commonmark/src/Extension/Table/TableSection.php
vendored
Normal file
66
vendor/league/commonmark/src/Extension/Table/TableSection.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Element\AbstractStringContainerBlock;
|
||||
use League\CommonMark\Block\Element\InlineContainerInterface;
|
||||
use League\CommonMark\ContextInterface;
|
||||
use League\CommonMark\Cursor;
|
||||
|
||||
final class TableSection extends AbstractStringContainerBlock implements InlineContainerInterface
|
||||
{
|
||||
const TYPE_HEAD = 'thead';
|
||||
const TYPE_BODY = 'tbody';
|
||||
|
||||
/** @var string */
|
||||
public $type = self::TYPE_BODY;
|
||||
|
||||
public function __construct(string $type = self::TYPE_BODY)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function isHead(): bool
|
||||
{
|
||||
return self::TYPE_HEAD === $this->type;
|
||||
}
|
||||
|
||||
public function isBody(): bool
|
||||
{
|
||||
return self::TYPE_BODY === $this->type;
|
||||
}
|
||||
|
||||
public function canContain(AbstractBlock $block): bool
|
||||
{
|
||||
return $block instanceof TableRow;
|
||||
}
|
||||
|
||||
public function isCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function matchesNextLine(Cursor $cursor): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRemainingContents(ContextInterface $context, Cursor $cursor): void
|
||||
{
|
||||
}
|
||||
}
|
||||
41
vendor/league/commonmark/src/Extension/Table/TableSectionRenderer.php
vendored
Normal file
41
vendor/league/commonmark/src/Extension/Table/TableSectionRenderer.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This is part of the league/commonmark package.
|
||||
*
|
||||
* (c) Martin Hasoň <martin.hason@gmail.com>
|
||||
* (c) Webuni s.r.o. <info@webuni.cz>
|
||||
* (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\Extension\Table;
|
||||
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use League\CommonMark\HtmlElement;
|
||||
|
||||
final class TableSectionRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
||||
{
|
||||
if (!$block instanceof TableSection) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
if (!$block->hasChildren()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$attrs = $block->getData('attributes', []);
|
||||
|
||||
$separator = $htmlRenderer->getOption('inner_separator', "\n");
|
||||
|
||||
return new HtmlElement($block->type, $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user