From 3a300ac19a9338c4e05fd1a8434309eb83805269 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 11 Sep 2024 11:19:33 +0200 Subject: [PATCH 1/2] Add support for tilde characters --- tests/IntegrationTest.php | 4 ++++ tests/fixtures/expected/blocks/nodes/text.html | 7 +++++++ tests/fixtures/source/blocks/nodes/text.rst | 7 +++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/fixtures/expected/blocks/nodes/text.html create mode 100644 tests/fixtures/source/blocks/nodes/text.rst diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index f121ba3..3045334 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -142,6 +142,10 @@ public function parserUnitBlockProvider() 'blockName' => 'nodes/span-link', ]; + yield 'text' => [ + 'blockName' => 'nodes/text', + ]; + yield 'title' => [ 'blockName' => 'nodes/title', ]; diff --git a/tests/fixtures/expected/blocks/nodes/text.html b/tests/fixtures/expected/blocks/nodes/text.html new file mode 100644 index 0000000..afc3337 --- /dev/null +++ b/tests/fixtures/expected/blocks/nodes/text.html @@ -0,0 +1,7 @@ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut enim ad minim +veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea +commodo consequat. Duis aute irure dolor in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur.

+ +

Excepteur ~1,000 sint! Occaecat cupidatat non proident, sunt in culpa qui officia +deserunt mollit anim id est laborum. áàâäãåéèêëíìîïóòôöõúùûüñçÿ

diff --git a/tests/fixtures/source/blocks/nodes/text.rst b/tests/fixtures/source/blocks/nodes/text.rst new file mode 100644 index 0000000..f5dbb33 --- /dev/null +++ b/tests/fixtures/source/blocks/nodes/text.rst @@ -0,0 +1,7 @@ +**Lorem ipsum** dolor sit amet, consectetur adipisicing elit. Ut enim ad minim +veniam, quis nostrud *exercitation ullamco laboris* nisi ut aliquip ex ea +commodo consequat. ``Duis aute irure dolor`` in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur. + +Excepteur ~1,000 sint! Occaecat cupidatat non proident, sunt in culpa qui officia +deserunt mollit anim id est laborum. áàâäãåéèêëíìîïóòôöõúùûüñçÿ From 9223ccc89e6c7b0ab78c0af755ce85ebaa918668 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Wed, 11 Sep 2024 15:51:17 +0200 Subject: [PATCH 2/2] Temporary replace tildes to avoid it being parsed as NBSP --- src/Renderers/SpanNodeRenderer.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Renderers/SpanNodeRenderer.php b/src/Renderers/SpanNodeRenderer.php index 65598bd..f9db721 100644 --- a/src/Renderers/SpanNodeRenderer.php +++ b/src/Renderers/SpanNodeRenderer.php @@ -42,6 +42,19 @@ public function __construct( $this->symfonyVersion = $symfonyVersion; } + public function render(): string + { + // Work around "~" being parsed as non-breaking space by rst-parser, + // while this is not part of the specification. + $spanValue = $this->span->getValue(); + $spanValue = str_replace('~', '__TILDE__', $spanValue); + $this->span->setValue($spanValue); + + $rendered = parent::render(); + + return str_replace('__TILDE__', '~', $rendered); + } + /** @inheritDoc */ public function link(?string $url, string $title, array $attributes = []): string {