1 | <?php |
||
7 | class TextConverter implements ConverterInterface |
||
8 | { |
||
9 | /** |
||
10 | * @param ElementInterface $element |
||
11 | * |
||
12 | * @return string |
||
13 | */ |
||
14 | 48 | public function convert(ElementInterface $element) |
|
15 | { |
||
16 | 48 | $value = $element->getValue(); |
|
17 | |||
18 | 48 | $markdown = preg_replace('~\s+~u', ' ', $value); |
|
19 | |||
20 | //escape the following characters: '*', '_' and '\' |
||
21 | 48 | $markdown = preg_replace('~([*_\\\\])~u', '\\\\$1', $markdown); |
|
22 | |||
23 | 48 | $markdown = preg_replace('~^#~u', '\\\\#', $markdown); |
|
24 | |||
25 | 48 | if ($markdown === ' ') { |
|
26 | $next = $element->getNext(); |
||
27 | if (!$next || $next->isBlock()) { |
||
28 | $markdown = ''; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | 48 | return $markdown; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * @return string[] |
||
37 | */ |
||
38 | 78 | public function getSupportedTags() |
|
42 | } |
||
43 |