Skip to content

Self-closing tags do not exist in HTML, warn/error when using them #95

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

Open
KieranP opened this issue Apr 19, 2025 · 1 comment
Open

Comments

@KieranP
Copy link

KieranP commented Apr 19, 2025

In the docs (https://herb-tools.dev/specification/html), it refers to <img /> and <div /> as self-closing tags. Except in HTML5 (the current standard), there is no such thing. It's a carry-over from the XHTML days, and it doesn't work as people expect.

Browsers interpret <div />Hello as <div>Hello</div>, <script />Hello as <script>Hello</script>, etc, leading to a lot of issues. More on that here: https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags

So I highly recommend that Herb throw warnings (maybe even errors) and link to the above developer docs when any "self-closing" tags are encountered. This would help the Rails community write more compliant HTML code.

@marcoroth
Copy link
Owner

Yeah I agree! This is a good idea. Thanks for opening this issue @KieranP!

I still haven't figured out 100% where this logic should go. Like, should this be as part of the parser directly or should this should be a lint-rule in the linter itself.

I guess what we could do for now, until we have the linter, is to add this logic to the parser itself, and then later once we have the linter, move the rule over.

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

No branches or pull requests

2 participants