Skip to content

feat_req(html): check whether a html attribute is boolean according to the spec #5658

@lowlighter

Description

@lowlighter

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:

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 as disabled="disabled" by most browsers, in addition to being technically incorrect
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feedback welcomeWe want community's feedback on this issue or PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions