@@ 20-39 (lines=20) @@ | ||
17 | use League\CommonMark\ElementRendererInterface; |
|
18 | use League\CommonMark\HtmlElement; |
|
19 | ||
20 | class TableCaptionRenderer implements BlockRendererInterface |
|
21 | { |
|
22 | public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) |
|
23 | { |
|
24 | if (!($block instanceof TableCaption)) { |
|
25 | throw new \InvalidArgumentException('Incompatible block type: '.get_class($block)); |
|
26 | } |
|
27 | ||
28 | $attrs = []; |
|
29 | foreach ($block->getData('attributes', []) as $key => $value) { |
|
30 | $attrs[$key] = $htmlRenderer->escape($value, true); |
|
31 | } |
|
32 | ||
33 | if ($block->id) { |
|
34 | $attrs['id'] = $block->id; |
|
35 | } |
|
36 | ||
37 | return new HtmlElement('caption', $attrs, $htmlRenderer->renderInlines($block->children())); |
|
38 | } |
|
39 | } |
|
40 |
@@ 20-39 (lines=20) @@ | ||
17 | use League\CommonMark\ElementRendererInterface; |
|
18 | use League\CommonMark\HtmlElement; |
|
19 | ||
20 | class TableCellRenderer implements BlockRendererInterface |
|
21 | { |
|
22 | public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) |
|
23 | { |
|
24 | if (!($block instanceof TableCell)) { |
|
25 | throw new \InvalidArgumentException('Incompatible block type: '.get_class($block)); |
|
26 | } |
|
27 | ||
28 | $attrs = []; |
|
29 | foreach ($block->getData('attributes', []) as $key => $value) { |
|
30 | $attrs[$key] = $htmlRenderer->escape($value, true); |
|
31 | } |
|
32 | ||
33 | if ($block->align) { |
|
34 | $attrs['align'] = $block->align; |
|
35 | } |
|
36 | ||
37 | return new HtmlElement($block->type, $attrs, $htmlRenderer->renderInlines($block->children())); |
|
38 | } |
|
39 | } |
|
40 |