mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
66 lines
1.2 KiB
PHP
66 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Erusev\Parsedown\Components\Inlines;
|
|
|
|
use Erusev\Parsedown\Components\Inline;
|
|
use Erusev\Parsedown\Html\Renderables\Text;
|
|
use Erusev\Parsedown\Parsing\Excerpt;
|
|
use Erusev\Parsedown\State;
|
|
|
|
final class EscapeSequence implements Inline
|
|
{
|
|
use WidthTrait;
|
|
|
|
const SPECIALS = '!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~';
|
|
|
|
/** @var string */
|
|
private $text;
|
|
|
|
/**
|
|
* @param string $text
|
|
*/
|
|
private function __construct($text)
|
|
{
|
|
$this->text = $text;
|
|
$this->width = 2;
|
|
}
|
|
|
|
/**
|
|
* @param Excerpt $Excerpt
|
|
* @param State $State
|
|
* @return static|null
|
|
*/
|
|
public static function build(Excerpt $Excerpt, State $State)
|
|
{
|
|
$char = \substr($Excerpt->text(), 1, 1);
|
|
|
|
if ($char !== '' && \strpbrk($char, self::SPECIALS) !== false) {
|
|
return new self($char);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/** @return string */
|
|
public function char()
|
|
{
|
|
return $this->text;
|
|
}
|
|
|
|
/**
|
|
* @return Text
|
|
*/
|
|
public function stateRenderable()
|
|
{
|
|
return new Text($this->char());
|
|
}
|
|
|
|
/**
|
|
* @return Text
|
|
*/
|
|
public function bestPlaintext()
|
|
{
|
|
return new Text($this->char());
|
|
}
|
|
}
|