singult icon indicating copy to clipboard operation
singult copied to clipboard

Singult doesn't recognize svg <animate> element

Open valyagolev opened this issue 11 years ago • 4 comments

Hello,

I may be doing something wrong, but I don't understand what.

I use c2 (and consequently singult) to create an <svg> element, which contains a <path> with <animate> in it. <path> is displayed just fine, however the newly-created <animate> element is not recognised by Chrome as an SVGElement and (consequently?) the animation doesn't happen at all.

I found out that if add the animate into re_svg_tags, like that:

re_svg_tags = /^(animate|svg|g|rect|circle|clipPath|path|line|polygon|polyline|text|textPath)$/;

it works really well.

Do you think it's a singult's issue, or I'm mis-using it somehow?

Thank you!

valyagolev avatar Jan 13 '14 07:01 valyagolev

Nope, you're using it exactly right and even found where you'd need to put the fix. If you want to submit a pull request for this, I'll happily accept it.

lynaghk avatar Jan 17 '14 21:01 lynaghk

Okay, thanks!

As this is probably not limited to animate, I was thinking about more general ways to solve the problem, e.g.:

  1. Exposing re_svg_tags to allow changing it from the user code, maybe as a mutable list, or with api
  2. Making inner elements influence the outer elements' namespace, e.g. everything inside <svg> is from its namespace
  3. Allowing namespaced tag names: [:svg:svg [:svg:animate ...]]
  4. Providing a special function/macro to transform the namespace of every inner tag: (namespaced :svg [:svg [:animate ...]]) (probably can be implemented in terms of 3)

I don't like 1, but it seems the simplest. I like 2 a lot, but I'm not sure if it's possible. I like 3 as well. If 3+2 could work that would be great; the next best thing could be 3+4.

What do you think? I'd be happy to work on this problem when I have time.

valyagolev avatar Jan 18 '14 07:01 valyagolev

  1. is the wrong solution (users shouldn't have to care)
  2. sounds too complex and magical to implement
  3. namespaced tags are already supported, so this option already exists; however, I think re_svg_tags should just cover all of the known SVG tags so that users don't have to think about it.
  4. Sounds complicated.

What about just filling out re_svg_tags with everything and then making it clear in the README that svg and html namespace prefixes are already available?

lynaghk avatar Jan 20 '14 18:01 lynaghk

I didn't know namespaced tags are supported, how could I not try, I'll use them for now:)

What about just filling out re_svg_tags with everything and then making it clear in the README that svg and html namespace prefixes are already available?

Well, they're namespaced for a reason, I guess, which is to avoid overlapping. There're some elements which are same in svg and html, e.g. a, script or title (see https://developer.mozilla.org/en-US/docs/Web/SVG/Element ). I'm not sure that's such a big issue, but we'll have to be careful about not accidentally adding the valid html tags there.

valyagolev avatar Jan 21 '14 16:01 valyagolev