|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the league/commonmark package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Davey Shafik <[email protected]> |
|
7
|
|
|
* (c) Colin O'Dell <[email protected]> |
|
8
|
|
|
* (c) Dan Hunsaker <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs) |
|
11
|
|
|
* - (c) John MacFarlane |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
14
|
|
|
* file that was distributed with this source code. |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Danhunsaker\Markua\Block\Renderer; |
|
18
|
|
|
|
|
19
|
|
|
use League\CommonMark\Block\Element\AbstractBlock; |
|
20
|
|
|
use League\CommonMark\Block\Renderer\BlockRendererInterface; |
|
21
|
|
|
use League\CommonMark\HtmlElement; |
|
22
|
|
|
use League\CommonMark\ElementRendererInterface; |
|
23
|
|
|
use League\CommonMark\Util\Xml; |
|
24
|
|
|
use Danhunsaker\Markua\Block\Element\Aside; |
|
25
|
|
|
|
|
26
|
|
|
class AsideRenderer implements BlockRendererInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @param Aside $block |
|
30
|
|
|
* @param ElementRendererInterface $htmlRenderer |
|
31
|
|
|
* @param bool $inTightList |
|
32
|
|
|
* |
|
33
|
|
|
* @return HtmlElement |
|
34
|
|
|
*/ |
|
35
|
30 |
|
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) |
|
36
|
|
|
{ |
|
37
|
30 |
|
if (!($block instanceof Aside)) { |
|
38
|
|
|
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
30 |
|
$attrs = []; |
|
42
|
30 |
|
foreach ($block->getData('attributes', []) as $key => $value) { |
|
43
|
|
|
$attrs[$key] = Xml::escape($value, true); |
|
44
|
30 |
|
} |
|
45
|
|
|
|
|
46
|
30 |
|
$filling = $htmlRenderer->renderBlocks($block->children()); |
|
|
|
|
|
|
47
|
30 |
|
if ($filling === '') { |
|
48
|
|
|
return new HtmlElement('aside', $attrs, $htmlRenderer->getOption('inner_separator', "\n")); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
30 |
|
return new HtmlElement( |
|
52
|
30 |
|
'aside', |
|
53
|
30 |
|
$attrs, |
|
54
|
30 |
|
$htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n") |
|
55
|
30 |
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: