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.

38 lines
857 B

  1. <?php
  2. namespace League\HTMLToMarkdown\Converter;
  3. use League\HTMLToMarkdown\ElementInterface;
  4. class ImageConverter implements ConverterInterface
  5. {
  6. /**
  7. * @param ElementInterface $element
  8. *
  9. * @return string
  10. */
  11. public function convert(ElementInterface $element)
  12. {
  13. $src = $element->getAttribute('src');
  14. $alt = $element->getAttribute('alt');
  15. $title = $element->getAttribute('title');
  16. if ($title !== '') {
  17. // No newlines added. <img> should be in a block-level element.
  18. $markdown = '![' . $alt . '](' . $src . ' "' . $title . '")';
  19. } else {
  20. $markdown = '![' . $alt . '](' . $src . ')';
  21. }
  22. return $markdown;
  23. }
  24. /**
  25. * @return string[]
  26. */
  27. public function getSupportedTags()
  28. {
  29. return array('img');
  30. }
  31. }