Skip to content
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

Closing HTML tag improperly formatted #2

Open
anthmatic opened this issue Apr 8, 2022 · 1 comment
Open

Closing HTML tag improperly formatted #2

anthmatic opened this issue Apr 8, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@anthmatic
Copy link
Contributor

Prettier's built-in HTML formatter has a known issue which sometimes causes closing HTML tags to be printed on two lines. For example:
<a class="blog-related-posts__title-link" href="{{ post.absolute_url }}">{{ post.name }}</a></h3>

becomes:

<a class="blog-post__tag-link" href="{{ blog_tag_url(group.id, tag.slug) }}" rel="tag"
            >{{ tag.name }}</a
          >

Reduced test case:
https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAeAhgAjAG3QZ3wF4AdEACzgE9MZyBLfTRzLHaAc2z0Mx0ZhlWMGACdSIdFAh04ogLTsoHeehGj6AIwCu8IWrESpMyguOyFSlQY069IAHwcAJi4Bm7jqgD06ByAAaEAgABxh6aHxkUHRRUQgAdwAFWIQolHQcBPQqKKDNUXQwAGs4GABldABbOAAZeig4ZDdM-Dh8wpKy8pCiho5kMW12kDgqzThnZ0naqQ5tdA44ADEIUSqDfuRJXQhAihgqnAB1Bnh8XrA4crT6cIA3O6pt-DF6MBh9hrbRGCTCjgbZqtEYAK3wAA9yv0cHAAIraGRNJAtHBtIK9UQ-bbkQ44fYhDSwY70Zx0ZAADgADBj4m1joUQttCXAfvcmkEAI6I+D-ULpST4eSNSaTfaiODc+gS-6LIEokFBNpVeiDUTDJUw+E85Go9EgGDoTQksnkZAAJiCYnQ9H4ygAwhAqvLRvgAKz7bRtAAqRvSepG92GAEkoNNYOUwBowgBBMPlGBUWHAtFwAC+aaAA

@anthmatic anthmatic added the bug Something isn't working label Apr 8, 2022
@anthmatic
Copy link
Contributor Author

After some digging it looks like there are two issues at play here:

  1. Prettier handles formatting for inline tags differently than block level tags in order to maintain whitespace as authored See: whitespace sensitive formatting

If the A tag get's authored like with line breaks, it should preserve them and avoid this output- but that might have whitespace implications in the rendered page.

<a>
 {{ Text }}
</a>
  1. There is ongoing debate that the closing tag should not wrap like that (see link above)- We'll need to wait this out to see how it's resolved.

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

No branches or pull requests

1 participant