Skip to content

Parser fails when template syntax exists within html tag #115

@tylermmorton

Description

@tylermmorton

Hi, firstly thank you for this plugin, it's a really great tool when working with Go HTML templates.

I noticed the parser falls over when template syntax exists within an HTML tag.

<button class="{{if eq .SelectedTab "docs"}}active {{end}}">
Hello world!
</button>

Here is the prettier output:

[error] test.tmpl.html: SyntaxError: Unexpected closing tag "button". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (3:1)
[error]   1 | <button class="{{if eq .SelectedTab "docs"}}active {{end}}">
[error]   2 |   Hello world!
[error] > 3 | </button>
[error]     | ^^^^^^^^^

Similarly,

<button
    {{if eq .SelectedTab "docs"}}data-tab-active{{end}}
    class="font-bold"
>
  Hello world!
</button>
[error] test.tmpl.html: SyntaxError: Unexpected closing tag "button". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (6:1)
[error]   4 | >
[error]   5 |   Hello world!
[error] > 6 | </button>
[error]     | ^^^^^^^^^

I would expect it to be able to handle the first case, as the template syntax is within the class string. The second use case would be the preferred approach but I can understand if this is harder to parse and handle within Prettier.

Would love any insights on how to solve for this. I'm happy to contribute back as well if you can point me in the right direction.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions