Open christophhagen opened 1 month ago
Hi, thanks for engaging!
That is the exact reason I did not include SVG stuff yet, because it behaves differently in subtle ways. HTML "prefers" no trailing slash for unpaired tags, but XML-like things like SVG require them....
So I wasn't sure if adding svg into the regular some HTML
system is a good idea, or rather have a completely separate SVGBuilder
approach. Also, the global namespace is littered enough as it is already by importing Elementary in a file, adding all the svg tags as well feels a bit much to me - especially since they can only be used within very narrow constraints.
In my projects, I just include things like
HTMLRaw("svg \(withParameters) goes here")
but that's obviously not the nicest.
Pro tip, for better (static) svg caching I use this trick actually (loads the actual svg from a cache-controlled file)
struct MyLogo: HTML {
var size: Int = 60
var basePath: String
var content: some HTML {
HTMLRaw("""
<svg width="\(self.size)" height="\(self.size)" class="fill-green-500">
<use xlink:href="\(self.basePath)/my-logo.svg#logo"></use>
</svg>
""")
}
}
To summarize, I don't yet see a great way forward, but I am leaning towards having a completely separate SVG module.
Okay, good to know. I'll use HTMLTrait.Paired
for now, until I find the time to work on a better system for me.
First off, thanks for starting this library. I'm currently experimenting with it to generate HTML pages with swift, and ran across an issue:
I created a custom
path
element to write inline svg:I can then write simple
svg
content:Once I render this, it produces the following HTML:
I think this is valid HTML, but if I try to display the svg in Safari, it doesn't render correctly. Apparently Safari needs a trailing slash for
path
, like so:Is there a way to force certain void elements to add a trailing slash when rendering? Or should I use a different approach?
I guess the alternative would be to use
HTMLTrait.Paired
instead ofHTMLTrait.Unpaired
, but that would make the HTML less compact.