|
7 | 7 | use League\CommonMark\MarkdownConverter; |
8 | 8 | use Symfony\Component\Stopwatch\Stopwatch; |
9 | 9 |
|
10 | | -final readonly class CommonMark implements MarkdownInterface |
| 10 | +final class CommonMark implements MarkdownInterface |
11 | 11 | { |
12 | 12 | public function __construct( |
13 | | - private MarkdownConverter $textConverter, |
14 | | - private MarkdownConverter $textExtraConverter, |
15 | | - private MarkdownConverter $lineConverter, |
16 | | - private MarkdownConverter $textHtmlConverter, |
17 | | - private MarkdownConverter $textExtraHtmlConverter, |
18 | | - private ?Stopwatch $stopwatch = null, |
| 13 | + private readonly MarkdownConverter $textConverter, |
| 14 | + private readonly MarkdownConverter $textExtraConverter, |
| 15 | + private readonly MarkdownConverter $lineConverter, |
| 16 | + private readonly ?Stopwatch $stopwatch = null |
19 | 17 | ) { |
20 | 18 | } |
21 | 19 |
|
22 | | - #[\Override] |
23 | | - public function text(?string $markdown = null, bool $allowHtml = false): string |
| 20 | + public function text(string $markdown = null): string |
24 | 21 | { |
25 | 22 | if (null === $markdown) { |
26 | 23 | return ''; |
27 | 24 | } |
28 | | - $this->stopwatch?->start(CommonMark::class.'::text'); |
29 | | - $converter = $allowHtml ? $this->textHtmlConverter : $this->textConverter; |
30 | | - $html = $converter->convert($markdown)->getContent(); |
31 | | - $this->stopwatch?->stop(CommonMark::class.'::text'); |
32 | | - |
| 25 | + $this->stopwatch?->start(CommonMark::class . '::text'); |
| 26 | + $html = $this->textConverter->convert($markdown)->getContent(); |
| 27 | + $this->stopwatch?->stop(CommonMark::class . '::text'); |
33 | 28 | return $html; |
34 | 29 | } |
35 | 30 |
|
36 | | - #[\Override] |
37 | | - public function textExtra(?string $markdown = null, bool $allowHtml = false): string |
| 31 | + public function textExtra(string $markdown = null): string |
38 | 32 | { |
39 | 33 | if (null === $markdown) { |
40 | 34 | return ''; |
41 | 35 | } |
42 | | - $this->stopwatch?->start(CommonMark::class.'::textExtra'); |
43 | | - $converter = $allowHtml ? $this->textExtraHtmlConverter : $this->textExtraConverter; |
44 | | - $html = $converter->convert($markdown)->getContent(); |
45 | | - $this->stopwatch?->stop(CommonMark::class.'::textExtra'); |
46 | | - |
| 36 | + $this->stopwatch?->start(CommonMark::class . '::textExtra'); |
| 37 | + $html = $this->textExtraConverter->convert($markdown)->getContent(); |
| 38 | + $this->stopwatch?->stop(CommonMark::class . '::textExtra'); |
47 | 39 | return $html; |
48 | 40 | } |
49 | 41 |
|
50 | | - #[\Override] |
51 | | - public function line(?string $markdown = null): string |
| 42 | + public function line(string $markdown = null): string |
52 | 43 | { |
53 | 44 | if (null === $markdown) { |
54 | 45 | return ''; |
55 | 46 | } |
56 | | - $this->stopwatch?->start(CommonMark::class.'::line'); |
| 47 | + $this->stopwatch?->start(CommonMark::class . '::line'); |
57 | 48 | $html = $this->lineConverter->convert($markdown)->getContent(); |
58 | | - $this->stopwatch?->stop(CommonMark::class.'::line'); |
59 | | - |
| 49 | + $this->stopwatch?->stop(CommonMark::class . '::line'); |
60 | 50 | return $html; |
61 | 51 | } |
62 | | - |
63 | | - #[\Override] |
64 | | - public function strip(?string $markdown = null): ?string |
65 | | - { |
66 | | - if (!is_string($markdown)) { |
67 | | - return null; |
68 | | - } |
69 | | - /* |
70 | | - * Strip Markdown syntax |
71 | | - */ |
72 | | - $markdown = $this->textExtra($markdown); |
73 | | - // replace BR with space to avoid merged words. |
74 | | - $markdown = str_replace(['<br>', '<br />', '<br/>'], ' ', $markdown); |
75 | | - $markdown = strip_tags($markdown); |
76 | | - /* |
77 | | - * Remove control characters (including DEL). |
78 | | - */ |
79 | | - $markdown = preg_replace('/[\x00-\x1F\x7F]/', '', $markdown); |
80 | | - |
81 | | - return $markdown; |
82 | | - } |
83 | 52 | } |
0 commit comments