Closed joycollector closed 4 years ago
Fixes #5
Thanks for the PR. Using $$props
was a brilliant idea. I didn't know of it.
But there seems to be a problem with your RegExp. If the tag was simply <svg>
with no props, it matches <svg><...
as the first group instead of <svg
as you might expect.
With <svg ...props>
, it correctly matches <svg ...props
as first group. Parsing XML with RegExp is a landmine regardless, and is why I'd been holding out. Could you wait until this weekend for a proper solution?
No problem. Updated regex to support additional cases. Worth to mention that I'm not "parsing" xml here. This is a simple string splitting before any ">".
Parsing XML with RegExp is a landmine regardless, and is why I'd been holding out. Could you wait until this weekend for a proper solution?
BTW I've also tried the solution with xmldom. But it looks like an overkill to me for such a task.
Modified approach to create svelte component.
I use regular expression to split svg into two parts (<svg..... ) and (>....). After that I'm using $$props to pass all props to the svg.
As result we are getting clean svg without wrapper with all passed properties.