Skip to content

feat: add Range to HTMLComment nodes#1229

Merged
joerdav merged 1 commit intoa-h:mainfrom
dgrundel:html-comments
Jul 28, 2025
Merged

feat: add Range to HTMLComment nodes#1229
joerdav merged 1 commit intoa-h:mainfrom
dgrundel:html-comments

Conversation

@dgrundel
Copy link
Copy Markdown
Contributor

Hi again, this adds a Range to the parser's HTMLComment nodes.

Note on testing:
I am planning to stick to reusing the existing unit tests and to just update to include ranges. I'm finding that the current set of tests have a good range of inputs. If I spot any missing edge cases, I'll add more tests. Obviously, I'm happy to add any additional tests that you feel are needed as well. Just let me know if you see any gaps.

Use case notes:
As noted previously, my particular use case for these ranges is for linting Templ code. With each of these PRs I'll add a few words on why a range is useful for this particular element (i.e. why would you want to lint this?)

In the case of HTML comments, you may want to create a rule to forbid them entirely, or at least to ensure that they do not contain commented code. In addition to bloating the payload you send to your visitors, HTML comments may also leak unnecessary information. In most cases -- at least in my organization -- Go comments are preferred.

@joerdav
Copy link
Copy Markdown
Collaborator

joerdav commented Jul 28, 2025

Great, this looks good thanks!

@joerdav joerdav merged commit 63d8ad2 into a-h:main Jul 28, 2025
5 checks passed
dgrundel added a commit to dgrundel/templ that referenced this pull request Jul 29, 2025
Co-authored-by: Daniel <daniel@grundel.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants