Copie de Tumblr sur Shaarli
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
976 B

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