mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Implement EscapeSequence
This commit is contained in:
parent
164a39f3e9
commit
79a38a1ebb
51
src/Components/Inlines/EscapeSequence.php
Normal file
51
src/Components/Inlines/EscapeSequence.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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] !== '[') {
|
||||
|
Loading…
Reference in New Issue
Block a user