1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\console; |
9
|
|
|
|
10
|
|
|
use cebe\markdown\block\FencedCodeTrait; |
11
|
|
|
use cebe\markdown\inline\CodeTrait; |
12
|
|
|
use cebe\markdown\inline\EmphStrongTrait; |
13
|
|
|
use cebe\markdown\inline\StrikeoutTrait; |
14
|
|
|
use yii\helpers\Console; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A Markdown parser that enhances markdown for reading in console environments. |
18
|
|
|
* |
19
|
|
|
* Based on [cebe/markdown](https://github.com/cebe/markdown). |
20
|
|
|
* |
21
|
|
|
* @author Carsten Brandt <[email protected]> |
22
|
|
|
* @since 2.0 |
23
|
|
|
*/ |
24
|
|
|
class Markdown extends \cebe\markdown\Parser |
25
|
|
|
{ |
26
|
|
|
use FencedCodeTrait; |
27
|
|
|
use CodeTrait; |
28
|
|
|
use EmphStrongTrait; |
29
|
|
|
use StrikeoutTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array these are "escapeable" characters. When using one of these prefixed with a |
33
|
|
|
* backslash, the character will be outputted without the backslash and is not interpreted |
34
|
|
|
* as markdown. |
35
|
|
|
*/ |
36
|
|
|
protected $escapeCharacters = [ |
37
|
|
|
'\\', // backslash |
38
|
|
|
'`', // backtick |
39
|
|
|
'*', // asterisk |
40
|
|
|
'_', // underscore |
41
|
|
|
'~', // tilde |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Renders a code block |
47
|
|
|
* |
48
|
|
|
* @param array $block |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
protected function renderCode($block) |
52
|
|
|
{ |
53
|
|
|
return Console::ansiFormat($block['content'], [Console::NEGATIVE]) . "\n\n"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
2 |
|
protected function renderParagraph($block) |
60
|
|
|
{ |
61
|
2 |
|
return rtrim($this->renderAbsy($block['content'])) . "\n\n"; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Renders an inline code span `` ` ``. |
66
|
|
|
* @param array $element |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function renderInlineCode($element) |
70
|
|
|
{ |
71
|
|
|
return Console::ansiFormat($element[1], [Console::UNDERLINE]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Renders empathized elements. |
76
|
|
|
* @param array $element |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function renderEmph($element) |
80
|
|
|
{ |
81
|
|
|
return Console::ansiFormat($this->renderAbsy($element[1]), [Console::ITALIC]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Renders strong elements. |
86
|
|
|
* @param array $element |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
protected function renderStrong($element) |
90
|
|
|
{ |
91
|
|
|
return Console::ansiFormat($this->renderAbsy($element[1]), [Console::BOLD]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Renders the strike through feature. |
96
|
|
|
* @param array $element |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
protected function renderStrike($element) |
100
|
|
|
{ |
101
|
|
|
return Console::ansiFormat($this->parseInline($this->renderAbsy($element[1])), [Console::CROSSED_OUT]); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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: