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.

51 line
1.2 KiB

  1. <?php
  2. namespace League\HTMLToMarkdown\Converter;
  3. use League\HTMLToMarkdown\Configuration;
  4. use League\HTMLToMarkdown\ConfigurationAwareInterface;
  5. use League\HTMLToMarkdown\ElementInterface;
  6. class DefaultConverter implements ConverterInterface, ConfigurationAwareInterface
  7. {
  8. const DEFAULT_CONVERTER = '_default';
  9. /**
  10. * @var Configuration
  11. */
  12. protected $config;
  13. /**
  14. * @param Configuration $config
  15. */
  16. public function setConfig(Configuration $config)
  17. {
  18. $this->config = $config;
  19. }
  20. /**
  21. * @param ElementInterface $element
  22. *
  23. * @return string
  24. */
  25. public function convert(ElementInterface $element)
  26. {
  27. // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents,
  28. // such as <span> nodes on their own. C14N() canonicalizes the node to a string.
  29. // See: http://www.php.net/manual/en/domnode.c14n.php
  30. if ($this->config->getOption('strip_tags', false)) {
  31. return $element->getValue();
  32. }
  33. return html_entity_decode($element->getChildrenAsString());
  34. }
  35. /**
  36. * @return string[]
  37. */
  38. public function getSupportedTags()
  39. {
  40. return array(self::DEFAULT_CONVERTER);
  41. }
  42. }