Move HTML to Markdown library to Composer
This commit is contained in:
parent
1ab28bbe03
commit
c9dafe3b4e
43 changed files with 2380 additions and 776 deletions
52
vendor/league/html-to-markdown/src/Converter/LinkConverter.php
vendored
Normal file
52
vendor/league/html-to-markdown/src/Converter/LinkConverter.php
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace League\HTMLToMarkdown\Converter;
|
||||
|
||||
use League\HTMLToMarkdown\ElementInterface;
|
||||
|
||||
class LinkConverter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(ElementInterface $element)
|
||||
{
|
||||
$href = $element->getAttribute('href');
|
||||
$title = $element->getAttribute('title');
|
||||
$text = trim($element->getValue());
|
||||
|
||||
if ($title !== '') {
|
||||
$markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
|
||||
} elseif ($href === $text && $this->isValidAutolink($href)) {
|
||||
$markdown = '<' . $href . '>';
|
||||
} else {
|
||||
$markdown = '[' . $text . '](' . $href . ')';
|
||||
}
|
||||
|
||||
if (!$href) {
|
||||
$markdown = html_entity_decode($element->getChildrenAsString());
|
||||
}
|
||||
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedTags()
|
||||
{
|
||||
return array('a');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $href
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidAutolink($href)
|
||||
{
|
||||
return preg_match('/^[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*/i', $href) === 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue