3 namespace League\HTMLToMarkdown\Converter;
5 use League\HTMLToMarkdown\ElementInterface;
7 class LinkConverter implements ConverterInterface
10 * @param ElementInterface $element
14 public function convert(ElementInterface $element)
16 $href = $element->getAttribute('href');
17 $title = $element->getAttribute('title');
18 $text = trim($element->getValue());
21 $markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
22 } elseif ($href === $text && $this->isValidAutolink($href)) {
23 $markdown = '<' . $href . '>';
25 $markdown = '[' . $text . '](' . $href . ')';
29 $markdown = html_entity_decode($element->getChildrenAsString());
38 public function getSupportedTags()
48 private function isValidAutolink($href)
50 return preg_match('/^[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*/i', $href) === 1;