| @@ 23-40 (lines=18) @@ | ||
| 20 | use League\CommonMark\HtmlElement; |
|
| 21 | use League\CommonMark\Util\Xml; |
|
| 22 | ||
| 23 | class TableRenderer implements BlockRendererInterface |
|
| 24 | { |
|
| 25 | public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) |
|
| 26 | { |
|
| 27 | if (!$block instanceof Table) { |
|
| 28 | throw new \InvalidArgumentException('Incompatible block type: '.get_class($block)); |
|
| 29 | } |
|
| 30 | ||
| 31 | $attrs = []; |
|
| 32 | foreach ($block->getData('attributes', []) as $key => $value) { |
|
| 33 | $attrs[$key] = Xml::escape($value); |
|
| 34 | } |
|
| 35 | ||
| 36 | $separator = $htmlRenderer->getOption('inner_separator', "\n"); |
|
| 37 | ||
| 38 | return new HtmlElement('table', $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 23-40 (lines=18) @@ | ||
| 20 | use League\CommonMark\HtmlElement; |
|
| 21 | use League\CommonMark\Util\Xml; |
|
| 22 | ||
| 23 | class TableRowRenderer implements BlockRendererInterface |
|
| 24 | { |
|
| 25 | public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) |
|
| 26 | { |
|
| 27 | if (!$block instanceof TableRow) { |
|
| 28 | throw new \InvalidArgumentException('Incompatible block type: '.get_class($block)); |
|
| 29 | } |
|
| 30 | ||
| 31 | $attrs = []; |
|
| 32 | foreach ($block->getData('attributes', []) as $key => $value) { |
|
| 33 | $attrs[$key] = Xml::escape($value); |
|
| 34 | } |
|
| 35 | ||
| 36 | $separator = $htmlRenderer->getOption('inner_separator', "\n"); |
|
| 37 | ||
| 38 | return new HtmlElement('tr', $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 23-44 (lines=22) @@ | ||
| 20 | use League\CommonMark\HtmlElement; |
|
| 21 | use League\CommonMark\Util\Xml; |
|
| 22 | ||
| 23 | class TableRowsRenderer implements BlockRendererInterface |
|
| 24 | { |
|
| 25 | public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false) |
|
| 26 | { |
|
| 27 | if (!$block instanceof TableRows) { |
|
| 28 | throw new \InvalidArgumentException('Incompatible block type: '.get_class($block)); |
|
| 29 | } |
|
| 30 | ||
| 31 | if (!$block->hasChildren()) { |
|
| 32 | return ''; |
|
| 33 | } |
|
| 34 | ||
| 35 | $attrs = []; |
|
| 36 | foreach ($block->getData('attributes', []) as $key => $value) { |
|
| 37 | $attrs[$key] = Xml::escape($value); |
|
| 38 | } |
|
| 39 | ||
| 40 | $separator = $htmlRenderer->getOption('inner_separator', "\n"); |
|
| 41 | ||
| 42 | return new HtmlElement($block->type, $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||