From 7fd6e0bb31c1a59afe5fbf4a7b107e52d32ef2f8 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 27 Jan 2019 18:41:06 +0000 Subject: [PATCH] Backslash escape like CommonMark --- src/Components/Inlines/EscapeSequence.php | 17 ++++++++--------- tests/data/escaping.html | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Components/Inlines/EscapeSequence.php b/src/Components/Inlines/EscapeSequence.php index 5008906..75ae4b8 100644 --- a/src/Components/Inlines/EscapeSequence.php +++ b/src/Components/Inlines/EscapeSequence.php @@ -4,7 +4,6 @@ namespace Erusev\Parsedown\Components\Inlines; use Erusev\Parsedown\AST\StateRenderable; use Erusev\Parsedown\Components\Inline; -use Erusev\Parsedown\Html\Renderables\RawHtml; use Erusev\Parsedown\Html\Renderables\Text; use Erusev\Parsedown\Parsing\Excerpt; use Erusev\Parsedown\State; @@ -13,17 +12,17 @@ final class EscapeSequence implements Inline { use WidthTrait, DefaultBeginPosition; - const SPECIALS = '\\`*_{}[]()>#+-.!|~'; + const SPECIALS = '!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'; /** @var string */ - private $html; + private $text; /** - * @param string $html + * @param string $text */ - public function __construct($html) + public function __construct($text) { - $this->html = $html; + $this->text = $text; $this->width = 2; } @@ -42,11 +41,11 @@ final class EscapeSequence implements Inline } /** - * @return RawHtml + * @return Text */ public function stateRenderable() { - return new RawHtml($this->html); + return new Text($this->text); } /** @@ -54,6 +53,6 @@ final class EscapeSequence implements Inline */ public function bestPlaintext() { - return new Text($this->html); + return new Text($this->text); } } diff --git a/tests/data/escaping.html b/tests/data/escaping.html index ab1c41f..c8fa585 100644 --- a/tests/data/escaping.html +++ b/tests/data/escaping.html @@ -1,6 +1,6 @@

escaped *emphasis*.

escaped \*emphasis\* in a code span

escaped \*emphasis\* in a code block
-

\ ` * _ { } [ ] ( ) > # + - . !

+

\ ` * _ { } [ ] ( ) > # + - . !

one_two one_two

one*two one*two

\ No newline at end of file