Skip to content

Address deprecation of spaceless tag #454

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 1 commit into from
Jul 4, 2023

Conversation

greg0ire
Copy link
Contributor

@greg0ire greg0ire commented Jul 4, 2023

Since Twig 2.7, the spaceless tag is deprecated in favor of the spaceless filter, or the apply tag with a spaceless argument. I picked the latter so as to still benefit from syntax highlighting.

This is the only deprecation I found while running the test suite with symfony/phpunit-bridge locally.

Copy link
Contributor

@linawolf linawolf left a comment

Choose a reason for hiding this comment

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

thanks for catching this!

@linawolf
Copy link
Contributor

linawolf commented Jul 4, 2023

By running a quick code search there seem to be more then just this one position of spaceless

@wouterj
Copy link
Contributor

wouterj commented Jul 4, 2023

Where possible, I would suggest to not use spaceless at all and either not care about the resulting HTML or use the whitespace control characters where whitespace matters in rendering (e.g. inline or in pre elements).

See also this comment: symfony-tools/docs-builder#80 (comment)

@greg0ire greg0ire marked this pull request as draft July 4, 2023 15:44
Since Twig 2.7, the spaceless tag is deprecated in favor of the
spaceless filter, or the apply tag with a spaceless argument. I picked
the latter so as to still benefit from syntax highlighting.
@greg0ire
Copy link
Contributor Author

greg0ire commented Jul 4, 2023

@linawolf good catch! Fixed

@linawolf @wouterj looking at occurrences of spaceless in the project, I'm not sure I 100% understand what it does. For instance, is it really needed here:

{% apply spaceless %}<br>{% endapply %}

I'm starting to wonder if we couldn't remove it in most cases.

@greg0ire
Copy link
Contributor Author

greg0ire commented Jul 4, 2023

We @wouterj I just talked to @linawolf , most tags are really necessary for inline tags, because for instance if you have **bold text**. followed by a dot, since most developers add a newline at EOF, there will be a newline at EOF in the template for the bold html inline tag. The end result will be this:

<p>
<strong>bold text</strong>
.
</p>

This means an unwanted space will appear between the text and the dot.

@greg0ire greg0ire marked this pull request as ready for review July 4, 2023 16:12
@linawolf
Copy link
Contributor

linawolf commented Jul 4, 2023

We do need spaceless tags in inline node rendering though. Most IDEs will automatically add an empty line at the end of each file. So twig inserts a newline after each textrole. HTML then interprets this newline as space even if there should be no space between the end of the textrole (for example bolt text) and the next char (for example a dot or brace).

@greg0ire
Copy link
Contributor Author

greg0ire commented Jul 4, 2023

Anyway, I think this is orthogonal to that PR

@linawolf linawolf merged commit be3bc5f into phpDocumentor:main Jul 4, 2023
@greg0ire greg0ire deleted the depr-spaceless branch July 4, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants