3 namespace League\HTMLToMarkdown\Converter;
5 use League\HTMLToMarkdown\ElementInterface;
7 class TextConverter implements ConverterInterface
10 * @param ElementInterface $element
14 public function convert(ElementInterface $element)
16 $markdown = $element->getValue();
18 // Remove leftover \n at the beginning of the line
19 $markdown = ltrim($markdown, "\n");
21 // Replace sequences of invisible characters with spaces
22 $markdown = preg_replace('~\s+~u', ' ', $markdown);
24 // Escape the following characters: '*', '_', '[', ']' and '\'
25 $markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown);
27 $markdown = preg_replace('~^#~u', '\\\\#', $markdown);
29 if ($markdown === ' ') {
30 $next = $element->getNext();
31 if (!$next || $next->isBlock()) {
42 public function getSupportedTags()
44 return array('#text');