feat: support Go comments within HTML tag attributes#1251
Conversation
Implements support for single-line (//) and multi-line (/* */) Go comments within HTML element attributes, addressing issue a-h#866. Changes: - Add AttributeComment type to represent comments within attributes - Update parser to recognize and handle comments between attributes - Update generator to skip comments during code generation - Add comprehensive test coverage This allows developers to add explanatory comments directly within HTML tags for better code documentation without affecting the generated output. Fixes a-h#866
|
Besides the 1 comment I think this looks good, @a-h any thoughts? |
|
Maybe could do with some tests with attribute values that contain |
added edge case tests in https://github.com/jackielii/templ/blob/feat/attribute-comments/generator/test-attribute-comments/template.templ#L41-L68 |
|
@a-h anything else you need? |
|
This is a really cool feature! Do we need anything else here? |
|
@joerdav - we discussed this one last Friday, right? IIRC, we said we'd merge it. I was a bit reluctant because it's hard to walk something back once you've added it, and it changes the syntax highlighting and some other stuff. |
|
I've been using this patch over a year now. I'm exclusive Neovim user, the treesitter already supports this. I think it's a natural extension to existing syntax: support commenting inside the HTML tag is less unexpected than not supporting it. |
|
Agreed. I'm merging this today, just fixing the conflicts. |
Keep both the attribute comment tests from this branch and the unquoted attribute tests from main. Update comment test expectations to include ValueRange and Range fields added in main.
Summary
Implements support for single-line (
//) and multi-line (/* */) Go comments within HTML element attributes, addressing issue #866.Problem
Previously, templ did not allow Go comments within HTML tag attributes, requiring developers to place comments above the element which wasn't always convenient for documenting specific attributes.
Solution
This PR adds support for Go-style comments directly within HTML tag attributes. The comments are parsed and stored in the AST but excluded from the generated output.
Example
Changes
AttributeCommenttype to represent comments within attributesgenerator/test-attribute-comments/Testing
Fixes #866