Stillat / vscode-antlers-language-server

Provides rich language features for Statamic's Antlers templating language, including code completions, syntax highlighting, and more.
https://antlers.dev
MIT License
36 stars 3 forks source link

Conditional tags throw 'Unexpected closing tag' error #77

Closed j-jalving closed 11 months ago

j-jalving commented 11 months ago

Describe the bug Antlers Prettier Plugin is having trouble with conditional tags.

Impacted Products Which Antlers Toolbox products does this bug apply to?

Versions and Other Plugins/Extensions Please include the product version you are reporting a bug for. If you are reporting a bug for products such as Antlers Toolbox for VS Code or the Antlers Prettier Plugin, please include a list of other configured extensions or plugins if you believe they are contributing to the problematic behavior.

To Reproduce Add this to a antlers file, or any other syntax using conditional tags.

<{{ url ? 'a href="{url}" target="_blank" title="{title}"' : 'span'}}>
 {{ title }}
</{{ url ? 'a' : 'span' }}>

Expected behavior I would expect the lines to be formatted, but an error is thrown:

[error] resources/views/partials/card.antlers.html: SyntaxError: Unexpected closing tag "a6k0xm0hxvkqgwyg4qofa". 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 (21:7)
[error]   19 | </afzn2to52eqnh9pdnq42jkaohkd2fa8nrcd2kahnmz0svoacd8rlyim8nykqxkqpegfgv0gvzpugkujhurwaqcllwwgr3coicw589oes0nedjz1uqqu9y9dfcshxy6duumjgzlqadxikkxvh1tgdltquzenyd0chxpua0n3loib8ptegcqgs3hf7gr6jnljinmgeqncefo42seyiefdhqngaku4gxdjfvkkumtrhomrkyyjprja8bgbybatlzgeipsonroh6ccyl23rbmmnlby2zoqaok9rtslpopakiprjja>
[error]   20 |
[error] > 21 |       </a6k0xm0hxvkqgwyg4qofa>
[error]      |       ^^^^^^^^^^^^^^^^^^^^^^^^
[error]   22 |     
[error]   23 | </afnwfgspzu3z7523uwguhekzgckmd2iwwujyzkxbjswgdymmqs1bd43nuzg670zub8ekta3jhk7evopg46efmldpxzj2bp94hjntd3po2ikciuy2x4rte8iylaz1euipj5jiazmskwriiktsovehzjpjg11pr7wdb0algry5fz3th0u1qly4mvywh9y7m2rom7mayjvqoonnprmtmonkhcatnij8dlfhusp2l1zekfqymw23i7lhc4u2mxnqppgxudlzky0pp5990n6kvxpz8rhrzy8zgck4oi3wctfpv0l3cuvrilttlav0vl3ecfwcijyd7hx8bxdmmuethlhwh82r4z7v7ul5ybtzol2zfq34nvd1fqkdz5dhjyj63x73jw7fm2sdpuq499coavghwbq1fnc3gzouq4zsd1bquoqcfrgy8dns3an5yfkvkgvwt9cmjbyzfpqsrjfosuskm0daa>
[error]   24 |
JohnathonKoster commented 11 months ago

The opening and closing "name" part of the conditional tag need to match, so something like would work:

<{{ url ? 'a' : 'span' }} other things here>
 {{ title }}
</{{ url ? 'a' : 'span' }}>

These sections of code can be ignored by the formatter using the following special Antlers comments:

{{# format-ignore-start #}}
Code to ignore
{{# format-ignore-end #}}

Having mixed open/closed tags like that is not supported by the Antlers formatter due to how its been implemented (Prettier itself does not like unexpected closing tags/etc.)

j-jalving commented 11 months ago

I understand, thanks for the suggestions to solve this