1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace League\HTMLToMarkdown\Converter; |
||
6 | |||
7 | use League\HTMLToMarkdown\ElementInterface; |
||
8 | |||
9 | class BlockquoteConverter implements ConverterInterface |
||
10 | { |
||
11 | public function convert(ElementInterface $element): string |
||
12 | { |
||
13 | // Contents should have already been converted to Markdown by this point, |
||
14 | 6 | // so we just need to add '>' symbols to each line. |
|
15 | |||
16 | $markdown = ''; |
||
17 | |||
18 | $quoteContent = \trim($element->getValue()); |
||
19 | 6 | ||
20 | $lines = \preg_split('/\r\n|\r|\n/', $quoteContent); |
||
21 | 6 | \assert(\is_array($lines)); |
|
22 | |||
23 | 6 | $totalLines = \count($lines); |
|
24 | |||
25 | 6 | foreach ($lines as $i => $line) { |
|
26 | $markdown .= '> ' . $line . "\n"; |
||
27 | 6 | if ($i + 1 === $totalLines) { |
|
28 | 6 | $markdown .= "\n"; |
|
29 | 6 | } |
|
30 | 6 | } |
|
31 | 4 | ||
32 | 4 | return $markdown; |
|
33 | } |
||
34 | 6 | ||
35 | /** |
||
36 | * @return string[] |
||
37 | */ |
||
38 | public function getSupportedTags(): array |
||
39 | { |
||
40 | 99 | return ['blockquote']; |
|
41 | } |
||
42 | } |
||
43 |