-
Notifications
You must be signed in to change notification settings - Fork 62
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
Provide escape hatch for non-standard HTML attributes #295
Comments
Another idea would be to use e.g. an underscore prefix as an escape hatch for arbitrary attributes, not unlike the treatment of <button _hx-post="/clicked" _hx-swap="outerHTML">
Click Me
</button> |
I was eager to push along using htmx with my existing tyxml-based rendering setups, thus the quick PR. I understand that the approach suggested above wasn't agreed to, but it was easy enough and a pretty tiny addition that can be stacked on top of HEAD as need be (just in case it is decided that supporting non-standard attributes is a non-goal after all). 👋 |
I agree it's a decent idea. The syntactic marker is rather reasonable. Another option, would be to have something of the form |
I don't personally find the floating attribute option compelling; the underscore prefix happens to rhyme nicely IMO with the escape hatch for attributes with reserved keyword names like FWIW, my plan was to tweak the PR to address the minor critiques you provided in #296 (comment) (once I got back to front-end-land, sometime this month hopefully). If you'd prefer to move forward with a floating attribute approach, then I can do that, but it will probably take a little longer since it is a distinct approach. |
Well, Maybe we should have another syntactic marker. |
Sure, that's why I said it rhymed; in both cases, we're saying something that the underlying language(s) do not allow in their "external" form.
I'd be happy with any alternative you'd prefer. The syntactic window is pretty narrow given what refmt will allow IIRC. |
CHANGES: * Update for OCaml 5.0 and drop support for OCaml 4.2.0 (ocsigen/tyxml#312 by @rr0gi) * Add additional variants to `linktype` for the `rel` attribute (Leon @LogicalOverflow Vack) * Expand options for `autocomplete` attribute on `<input>` elements (ocsigen/tyxml#302 by Aron @aronerben Erben) * Fix the SVG element `<animate>` (by the way, deprecate `animation` et al. in favor of `animate` et al.) (ocsigen/tyxml#306 by Idir @ilankri Lankri) * Add support for `dialog` element and `onclose` attribute (ocsigen/tyxml#301 by Julien Sagot) * Add an escape hatch for emitting attributes with non-standard names in jsx or ppx code (a leading `_` character on attribute name) (ocsigen/tyxml#295 Chas @cemerick Emerick) * Add support for `type` attribute on `<script>` elements (ocsigen/tyxml#293 by Ulrik @ulrikstrid Strid and Chas @cemerick Emerick) * Add svg `fill-rule` attribute (ocsigen/tyxml#294 by Eric @dedbox Griffis)
Hello, I am trying to use hyperscript with tyxml. My issue is that there is no support for alternatives like |
@ethanthoma Sure, I use hyperscript, too. Replied on the issue you created on the hyperscript repo, here. |
thanks @cemerick. I must admit not being fully convinced by the whole thing, I hoped we had a more straightforward general solution ... |
CHANGES: * Update for OCaml 5.0 and drop support for OCaml 4.2.0 (ocsigen/tyxml#312 by @rr0gi) * Add additional variants to `linktype` for the `rel` attribute (Leon @LogicalOverflow Vack) * Expand options for `autocomplete` attribute on `<input>` elements (ocsigen/tyxml#302 by Aron @aronerben Erben) * Fix the SVG element `<animate>` (by the way, deprecate `animation` et al. in favor of `animate` et al.) (ocsigen/tyxml#306 by Idir @ilankri Lankri) * Add support for `dialog` element and `onclose` attribute (ocsigen/tyxml#301 by Julien Sagot) * Add an escape hatch for emitting attributes with non-standard names in jsx or ppx code (a leading `_` character on attribute name) (ocsigen/tyxml#295 Chas @cemerick Emerick) * Add support for `type` attribute on `<script>` elements (ocsigen/tyxml#293 by Ulrik @ulrikstrid Strid and Chas @cemerick Emerick) * Add svg `fill-rule` attribute (ocsigen/tyxml#294 by Eric @dedbox Griffis)
Many Javascript libraries/frameworks depend upon HTML markup that includes non-standard attributes. Examples I've come across the past couple of days include:
Of course, tyxml rejects these attributes, e.g. this hello-world example from htmx:
It is desirable to be able to use tyxml and benefit from the things it does well, while still being able to produce markup as required by libraries like these.
Conceptually, these custom attributes are basically just
data-*
attributes, and so there's no need for tyxml to do any kind of validation or checking on their values. All that is required is for tyxml to pass them along unharmed.(The notion of configuring tyxml ppx and jsx-ppx (via dune ppx arguments) with a set of allowable additional attribute names was suggested in discord and discarded.)
The text was updated successfully, but these errors were encountered: