Skip to content

Add support for tilde characters #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

javiereguiluz
Copy link
Collaborator

@javiereguiluz javiereguiluz commented Sep 11, 2024

Related to

This PR adds a failing test that shows the issue. This is the output change that would make test pass:

-<p>Excepteur &nbsp;1,000 sint! ...
+<p>Excepteur ~1,000 sint! ...

@stof
Copy link
Member

stof commented Sep 11, 2024

doctrine/rst-parser parses ~ as a non-breaking space. this was introduced in doctrine/rst-parser#42 but I have no idea where this comes from. I see no mention of non-breaking spaces in the reStructuredText documentation on the Sphinx website or on https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html.

@stof
Copy link
Member

stof commented Sep 11, 2024

even worse, I see no way of escaping a ~ in the rst-parser library.

@stof
Copy link
Member

stof commented Sep 11, 2024

Maybe it would make sense to investigate migrating to phpdocumentor/guides as the implementation of the docs-builder

@OskarStark OskarStark added bug Something isn't working bug in parser labels Sep 11, 2024
@wouterj
Copy link
Contributor

wouterj commented Sep 11, 2024

Maybe it would make sense to investigate migrating to phpdocumentor/guides as the implementation of the docs-builder

We're already working on this (see https://github.com/wouterj/symfony-docs-guides), but more work is needed here (especially around ordering documents).

@wouterj
Copy link
Contributor

wouterj commented Sep 11, 2024

I've pushed a not-so-nice workaround to this PR. I don't see any other way to escape the tilde, and it should be safe given this is the Symfony docs specific builder.


$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!

@javiereguiluz
Copy link
Collaborator Author

Thanks @wouterj for this contribution. Yes, I think this is a reasonable solution while we keep using the old RST parser. Thanks!

@javiereguiluz javiereguiluz merged commit 8fccaf0 into symfony-tools:main Sep 12, 2024
2 of 3 checks passed
@javiereguiluz javiereguiluz deleted the tilde branch September 12, 2024 09:28
@javiereguiluz
Copy link
Collaborator Author

This is now merged. Wouter, thanks for providing a solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug in parser bug Something isn't working
Development

Successfully merging this pull request may close these issues.

4 participants