Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Renderers/SpanNodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hope that we won't have content containing the actual text __TILDE__ in the symfony documentation (or the documentation of other projects built with this builder).
Maybe we should check for __TILDE__ in the spanValue before doing the ~ replacement and failing explicitly instead of producing a wrong output (or even smarter: selecting another non-conflicting placeholder in that case, but that might not be worth it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably safe to use this ... but if we want to assure this, we could use more underscores instead of only 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I would add least add the safety check to rebuild a build failure in case the assumption is not actually safe (instead of waiting for someone to discover that some obscure page has content not rendered like the source:

if (str_contains($spanValue, '__TILDE__')) {
    throw new \Exception('Cannot render content containing the text "__TILDE__" as it is used as a special placeholder in the build.');
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof OK, I've added your code while merging as an extra protection measure. Thanks!

}

/** @inheritDoc */
public function link(?string $url, string $title, array $attributes = []): string
{
Expand Down
4 changes: 4 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public function parserUnitBlockProvider()
'blockName' => 'nodes/span-link',
];

yield 'text' => [
'blockName' => 'nodes/text',
];

yield 'title' => [
'blockName' => 'nodes/title',
];
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/expected/blocks/nodes/text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><strong>Lorem ipsum</strong> dolor sit amet, consectetur adipisicing elit. Ut enim ad minim
veniam, quis nostrud <em>exercitation ullamco laboris</em> nisi ut aliquip ex ea
commodo consequat. <code translate="no" class="notranslate">Duis aute irure dolor</code> in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.</p>

<p>Excepteur ~1,000 sint! Occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum. áàâäãåéèêëíìîïóòôöõúùûüñçÿ</p>
7 changes: 7 additions & 0 deletions tests/fixtures/source/blocks/nodes/text.rst
Original file line number Diff line number Diff line change
@@ -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. áàâäãåéèêëíìîïóòôöõúùûüñçÿ
Loading