1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Implement EscapeSequence

This commit is contained in:
Aidan Woods 2019-01-20 02:35:03 +00:00
parent 164a39f3e9
commit 79a38a1ebb
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 51 additions and 10 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace Erusev\Parsedown\Components\Inlines;
use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
final class EscapeSequence implements Inline
{
use WidthTrait, DefaultBeginPosition;
const SPECIALS = '\\`*_{}[]()>#+-.!|~';
/** @var string */
private $html;
/**
* @param string $html
*/
public function __construct($html)
{
$this->html = $html;
$this->width = 2;
}
/**
* @param Excerpt $Excerpt
* @param State $State
* @return static|null
*/
public static function build(Excerpt $Excerpt, State $State)
{
if (isset($Excerpt->text()[1]) and \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
return new self($c);
}
return null;
}
/**
* @return RawHtml
*/
public function stateRenderable(Parsedown $_)
{
return new RawHtml($this->html);
}
}

View File

@ -411,16 +411,6 @@ class Parsedown
return $Elements;
}
protected function inlineEscapeSequence($Excerpt)
{
if (isset($Excerpt['text'][1]) and \in_array($Excerpt['text'][1], $this->specialCharacters, true)) {
return [
'element' => ['rawHtml' => $Excerpt['text'][1]],
'extent' => 2,
];
}
}
protected function inlineImage($Excerpt)
{
if (! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') {