Skip to content
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

Missing media attribute for the meta tag #31

Open
kevinrenskers opened this issue Jul 15, 2021 · 4 comments
Open

Missing media attribute for the meta tag #31

kevinrenskers opened this issue Jul 15, 2021 · 4 comments

Comments

@kevinrenskers
Copy link
Contributor

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?

@kevinrenskers
Copy link
Contributor Author

Luckily it is possible after all with customAttributes 😅

@chriseidhof
Copy link
Collaborator

That's what I've done as well for similar issues. I think the attributes are generated automatically from a list (here), 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
Copy link
Owner

robb commented Jul 18, 2021

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.:

 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 vs name) and that some of the definitions are in different specs, e.g. role is defined in the ARIA spec.

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
Copy link
Owner

robb commented Jul 18, 2021

Luckily it is possible after all with customAttributes 😅

Yup, I think having an escape hatch is always important for this kind of API design.

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

3 participants