1 | <?php |
||
17 | class TextParser extends BBCodeConverter implements TextParserInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @param string $text |
||
22 | * |
||
23 | * @return string |
||
24 | */ |
||
25 | public static function escape($text) |
||
26 | { |
||
27 | $text = preg_replace('/(?P<char>(?:_|\*))(.+?)(?P=char)/isu', '\\\$1$2\\\$1', $text); |
||
28 | $text = preg_replace('/\*\*(.+?)\*\*/isu', '*\\*$1*\\*', $text); |
||
29 | $text = preg_replace('/\-\-(\-)+/isu', '\-\-\-', $text); |
||
30 | $text = preg_replace('/\n*^(?!\w\s+)(#)/isu', '\\#', $text); |
||
31 | $text = preg_replace('/\[(.*?)\]\((.*?)\)/isu', '\\[$1\\]\\($2\\)', $text); |
||
32 | |||
33 | return $text; |
||
34 | } |
||
35 | |||
36 | public function __construct() {} |
||
37 | |||
38 | /** |
||
39 | * @brief replace BBCode user. |
||
40 | */ |
||
41 | protected function removeUser() { |
||
54 | |||
55 | /** |
||
56 | * @brief replace BBCode pre. |
||
57 | */ |
||
58 | protected function removePre() { |
||
69 | |||
70 | /** |
||
71 | * @brief replace BBCode header. |
||
72 | */ |
||
73 | protected function removeHeader() { |
||
86 | |||
87 | public function toMarkdown() |
||
96 | |||
97 | /** |
||
98 | * @param string $message |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function parse(string $message) |
||
108 | } |