Missing media attribute for the meta tag

#31 ยท open ยท 4 comments

View on GitHub โ†—

kevinrenskers

The "media" attribute is not available for meta tags, so something like this is currently impossible: ``` <meta name="theme-color" content="#ecd96f" media="(prefers-color-scheme: light)"> <meta name="theme-color" content="#0b3e05" media="(prefers-color-scheme: dark)"> ``` Would you want me to create a PR?

Comments

kevinrenskers

Luckily it is possible after all with `customAttributes` ๐Ÿ˜…

chriseidhof

That's what I've done as well for similar issues. I think the attributes are generated automatically from a list ([here](https://github.com/robb/Swim/blob/main/Generator/Sources/Generator/Definitions.swift)), but I'm not sure how @robb compiled that list or how we can add stuff. In my code base, I used `property`, `label`, `autocorrect` and some custom data properties. Using custom attributes works fine for that, although I also don't mind creating a PR.

robb

To add properties, you would have to add them to the `extension` on `Attribute` in https://github.com/robb/Swim/blob/main/Generator/Sources/Generator/Definitions.swift, then add them to the Tag definition, e.g.: ```diff static let meta = Tag( name: "Meta", description: "Text metadata.", - attributes: .charset, .content, .httpEquiv, .name5 + attributes: .charset, .content, .httpEquiv, .name5, .media properties: .emptyElement ) ``` (If you do, please keep everything alphabetized) I took the list from the WHATWG, don't remember exactly which version but something like this: https://html.spec.whatwg.org/review-drafts/2020-01/#elements-3 Not super happy with the current state of things, maybe this could be ported to a couple of XML or JSON files to generate the attributes from? Part of the complexity lies in different semantics for attributes with the same name on different tags (e.g. [`name`](https://html.spec.whatwg.org/review-drafts/2020-01/#attr-fe-name) vs [`name`](https://html.spec.whatwg.org/review-drafts/2020-01/#attr-iframe-name)) and that some of the definitions are in different specs, e.g. `role` is defined in [the ARIA spec](https://www.w3.org/TR/wai-aria-1.1/#host_general_role). Ideally, we would also be able to automatically perform safe conversions, e.g. from `URL` or `Int` to `String` but so far, it did seem to be a huge problem in practice.

robb

> Luckily it is possible after all with customAttributes ๐Ÿ˜… Yup, I think having an escape hatch is always important for this kind of API design.