deno_std
deno_std copied to clipboard
feat_req(html): check whether a html attribute is boolean according to the spec
Is your feature request related to a problem? Please describe.
I hope the pandora box wasn't opened with #5437, but I was hoping for some utilitary function that'd be able to tell if an html attribute for a given tagname is a boolean attribute or not.
Spec refs:
- https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attribute
- https://html.spec.whatwg.org/#attributes-3
The second link is a table containing a list of tagname/attributes and allowed values which can be used as reference. It is complete enough to also implement other utilities function.
Why the focus on boolean attributes ?
- These can often be misused, because of how boolean attributes are handled in html: a falsy value is when it is omitted, while a truthy value is its presence (including empty value or its name itself)
- e.g.
disabled="false"is actually treated asdisabled="disabled"by most browsers, in addition to being technically incorrect
- e.g.
- Such a function could be used for simple linting/formatting/sanitizing/testing tools, helping when generating html templates, etc.
- It makes the scope relatively small for now if std thinks this can be in-scope for the html package
As the spec is well-defined, it wouldn't require much maintenance, while once again abstracting the complexity of the html spec for users.
Describe the solution you'd like
Something along:
isBooleanAttribute("VIDEO", "playsinline") // true
isBooleanAttribute("DIV", "playsinline") // false
Describe alternatives you've considered
There's is-boolean-attribute but technically it's not compliant since it doesn't check the tagname