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
46
vendor/league/html-to-markdown/src/Converter/TextConverter.php
vendored
Normal file
46
vendor/league/html-to-markdown/src/Converter/TextConverter.php
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace League\HTMLToMarkdown\Converter;
|
||||
|
||||
use League\HTMLToMarkdown\ElementInterface;
|
||||
|
||||
class TextConverter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(ElementInterface $element)
|
||||
{
|
||||
$markdown = $element->getValue();
|
||||
|
||||
// Remove leftover \n at the beginning of the line
|
||||
$markdown = ltrim($markdown, "\n");
|
||||
|
||||
// Replace sequences of invisible characters with spaces
|
||||
$markdown = preg_replace('~\s+~u', ' ', $markdown);
|
||||
|
||||
// Escape the following characters: '*', '_', '[', ']' and '\'
|
||||
$markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown);
|
||||
|
||||
$markdown = preg_replace('~^#~u', '\\\\#', $markdown);
|
||||
|
||||
if ($markdown === ' ') {
|
||||
$next = $element->getNext();
|
||||
if (!$next || $next->isBlock()) {
|
||||
$markdown = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedTags()
|
||||
{
|
||||
return array('#text');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue