Copie de Tumblr sur Shaarli
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

43 行
923 B

  1. <?php
  2. namespace League\HTMLToMarkdown\Converter;
  3. use League\HTMLToMarkdown\ElementInterface;
  4. class TextConverter implements ConverterInterface
  5. {
  6. /**
  7. * @param ElementInterface $element
  8. *
  9. * @return string
  10. */
  11. public function convert(ElementInterface $element)
  12. {
  13. $value = $element->getValue();
  14. $markdown = preg_replace('~\s+~u', ' ', $value);
  15. //escape the following characters: '*', '_' and '\'
  16. $markdown = preg_replace('~([*_\\\\])~u', '\\\\$1', $markdown);
  17. $markdown = preg_replace('~^#~u', '\\\\#', $markdown);
  18. if ($markdown === ' ') {
  19. $next = $element->getNext();
  20. if (!$next || $next->isBlock()) {
  21. $markdown = '';
  22. }
  23. }
  24. return $markdown;
  25. }
  26. /**
  27. * @return string[]
  28. */
  29. public function getSupportedTags()
  30. {
  31. return array('#text');
  32. }
  33. }