Skip to content

[WIP] Fix missing line break with anchors #80

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 4 commits into from
Mar 19, 2021

Conversation

weaverryan
Copy link
Contributor

@weaverryan weaverryan commented Mar 19, 2021

This fixes #37

But... the fix should maybe go upstream to docrtrine... and I don't quite understand it. I included some test normalization in this PR, but the ACTUAL bug fix was to copy the paragraph.html.twig template from rst-parser into our project and customize it. Here are the changes:

-{% apply spaceless %}
    {% set text = paragraphNode.value.render()|trim %}

    {% if text %}
        <p{% if paragraphNode.classes %} class="{{ paragraphNode.classesString }}"{% endif %}>{{ text|raw }}</p>
    {% endif %}
-{% endapply %}

Yes, the spaceless was having bad side effects. What would happen is that the text variable would be set to something like this (with line breaks):

<p>Next, create the template with <code translate="no" class="notranslate">details</code>
<a href="https://symfony.com/doc/current/bundles/EasyAdminBundle/crud.html" class="reference external">CRUD pages</a>.</p>

The line break caused the word details and CRUD to have a space between them. But the spaceless killed that.

Are we somehow misusing / abusing spaceless? Should we remove all the spaceless upstream in the Doctrine templates?

Silly spacing thing in test depends on doctrine/rst-parser#141

Cheers!

@weaverryan weaverryan changed the title [WIP] Failing test case for a missing line break with anchors [WIP] Fix missing line break with anchors Mar 19, 2021
@weaverryan weaverryan force-pushed the missing-line-break-anchor branch from 66936df to 7554075 Compare March 19, 2021 02:09
@javiereguiluz
Copy link
Collaborator

Thanks for taking care of this one.

About spaces ... I don't know if it's possible, but my opinion would be to never deal with spaces manually unless it's required (e.g. inside a <code> or <pre> because spaces are significant or inside a <a> because additional spaces are visible if you use text underline).

@weaverryan
Copy link
Contributor Author

About spaces ... I don't know if it's possible

@javiereguiluz do you mean that you would prefer that the templates never use the spaceless filter? Or are you saying something else?

Thanks!

@weaverryan weaverryan force-pushed the missing-line-break-anchor branch from 7554075 to b3e4598 Compare March 19, 2021 16:33
@javiereguiluz
Copy link
Collaborator

Yes, I meant that ... but maybe now that we already use spaceless, it's smarter to just remove it where it makes sense and keep the rest.

@weaverryan weaverryan changed the base branch from master to main March 19, 2021 17:47
@weaverryan weaverryan force-pushed the missing-line-break-anchor branch from b3e4598 to 107fe8b Compare March 19, 2021 17:56
@weaverryan
Copy link
Contributor Author

Ok, for now, let's handle this in our repo, removing spaceless on a case-by-case basis :)

@weaverryan weaverryan merged commit 9e8c89f into main Mar 19, 2021
@weaverryan weaverryan deleted the missing-line-break-anchor branch March 19, 2021 17:57
@stof
Copy link
Member

stof commented Mar 24, 2021

Spaceless is about removing spaces between sibling HTML tags. but when these tags are inline elements, the whitespaces are relevant to the rendering.
Removing the spaceless filtering on a case by case basis would also require removing in any parent in the rendering.

In my experience, lots of cases using spaceless are using it to remove the template indentation, which is a misuse for 2 reasons:

  • the indentation might not be between 2 tags (see for instance the code snippet in this issue, where the indentation is before the first tag of the filtered content)
  • it removes much more spaces (it can remove spaces in the content rendered by the text variable, which is the case here)

The proper solution to remove spaces introduced by template indentation is to use the Twig whitespace control feature instead (which also has the nice performance benefit of being a compile-time feature rather than a runtime one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Minor issue when parsing a reference
3 participants