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

Support XML Elements #132

Closed
tgrosinger opened this issue Apr 30, 2023 · 7 comments
Closed

Support XML Elements #132

tgrosinger opened this issue Apr 30, 2023 · 7 comments

Comments

@tgrosinger
Copy link

Hello, thank you for this excellent library.

I'm trying to use gomponents to build an RSS XML along side my web site. The XML requires a <link></link> element, however gomponents is not rendering this correctly because it's considered a voidElement in HTML.

So far the best option I've thought of for fixing this is duplicating the El function to create XMLEl which does not use the isVoidElement check. But I would love to hear if you have another suggestion.

Thanks!

@markuswustenberg
Copy link
Member

Hi @tgrosinger . Hmm, yeah, the library is really geared towards HTML5 use, but I've hit the use case before. I have an SVG package in the repo which would potentially hit the same issue.

Maybe I could consider making an XML package that renders slightly differently, I'll think about that. I would think it would have more or less the same API, without the HTML-specific parts, and probably no helpers, so it would be pretty easy to implement.

@markuswustenberg
Copy link
Member

I'm playing with an implementation here: https://github.com/maragudk/gomponents-xml/pull/1

Not sure how I'm going to keep code duplication down, but maybe it doesn't matter. Or maybe I should just incorporate it in this repo… (I'm thinking out loud.)

@tgrosinger
Copy link
Author

It's not very clean at all, but this change did fix the issue for me: https://github.com/tgrosinger/gomponents/commit/b8a83564c297b77523b7944ad5c97fbb1329ca13

I think if renderChild were exported it would be much easier to reduce the duplication. Then I might suggest creating an xml package as a sibling to the svg and html packages.

@tgrosinger
Copy link
Author

Alternatively, this might also relate to #124 and possibly moving where the void element checking occurs and moving it out closer to the specific element type. That might be harder to do without changing the API though.

@markuswustenberg
Copy link
Member

@tgrosinger Both good points. For me, it's important that the focus of the library is HTML, and having something like XML support is nice, but not central to it.

I don't want to pollute the public API with XML-specific stuff that would confuse other users, but maybe I can pull the rendering logic into an internal package and thus have it available both from the xml and core package. That would also clean up the svg package, which similarly doesn't have void elements.

That actually seems like a feasible solution. I'll play around with it when I get some time, hopefully next week.

@tgrosinger
Copy link
Author

Sounds great. Thank you very much for looking at this!

@markuswustenberg
Copy link
Member

@tgrosinger I played around with this a bit, but quickly ran into problems with import cycles when pulling out the rendering logic. I'm not currently sure about a path forward without breaking the API (not an option), exposing rendering logic in the API (not a huge fan of that, since the focus is definitely HTML and would be totally irrelevant to those consumers), or duplicating a lot of code (also not a huge fan of that). I'll think about it some more, and suggestions are also welcome. 😊

@markuswustenberg markuswustenberg closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
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

2 participants