Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
MarkdownFunction | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
5.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFunctionName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
functionBlockBodyImpl | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
3.01 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Mvc\Template\Plugin; |
6 | |
7 | use PeServer\Core\Collection\Arr; |
8 | use PeServer\Core\Mvc\Markdown; |
9 | use PeServer\Core\Text; |
10 | use PeServer\Core\TypeUtility; |
11 | use PeServer\Core\Mvc\Template\Plugin\TemplatePluginArgument; |
12 | use PeServer\Core\Mvc\Template\Plugin\TemplateBlockFunctionBase; |
13 | |
14 | class MarkdownFunction extends TemplateBlockFunctionBase |
15 | { |
16 | public function __construct(TemplatePluginArgument $argument) |
17 | { |
18 | parent::__construct($argument); |
19 | } |
20 | |
21 | #region TemplateBlockFunctionBase |
22 | |
23 | public function getFunctionName(): string |
24 | { |
25 | return 'markdown'; |
26 | } |
27 | |
28 | protected function functionBlockBodyImpl(string $content): string |
29 | { |
30 | /** @var string */ |
31 | $className = $this->params['class'] ?? Text::EMPTY; |
32 | if (Text::isNullOrWhiteSpace($className)) { |
33 | $className = 'markdown'; |
34 | } elseif (!Text::contains($className, 'markdown', false)) { |
35 | $className = 'markdown ' . $className; |
36 | } |
37 | |
38 | $isSafeMode = TypeUtility::parseBoolean($this->params['safe_mode'] ?? true); |
39 | |
40 | $markdown = new Markdown(); |
41 | $markdown->setSafeMode($isSafeMode); |
42 | $result = $markdown->build($content); |
43 | $html = '<section class="' . $className . '">' . $result . '</section>'; |
44 | |
45 | return $html; |
46 | } |
47 | |
48 | #endregion |
49 | } |