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