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.

43 lines
964B

  1. <?php
  2. namespace League\HTMLToMarkdown\Converter;
  3. use League\HTMLToMarkdown\ElementInterface;
  4. class LinkConverter implements ConverterInterface
  5. {
  6. /**
  7. * @param ElementInterface $element
  8. *
  9. * @return string
  10. */
  11. public function convert(ElementInterface $element)
  12. {
  13. $href = $element->getAttribute('href');
  14. $title = $element->getAttribute('title');
  15. $text = $element->getValue();
  16. if ($title !== '') {
  17. $markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
  18. } elseif ($href === $text) {
  19. $markdown = '<' . $href . '>';
  20. } else {
  21. $markdown = '[' . $text . '](' . $href . ')';
  22. }
  23. if (!$href) {
  24. $markdown = html_entity_decode($element->getChildrenAsString());
  25. }
  26. return $markdown;
  27. }
  28. /**
  29. * @return string[]
  30. */
  31. public function getSupportedTags()
  32. {
  33. return array('a');
  34. }
  35. }