b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
425 stars 47 forks source link

SVG Support? #81

Open apowers313 opened 2 years ago

apowers313 commented 2 years ago

I'm trying to use d3 for SSR. The most likely path to success is to d3's SVG, but when I try to do this with deno-dom I run into an error that SVG namespaces are unimplemented.

Would this be something quick and easy to implement?

b-fuze commented 2 years ago

No, it won't be quick and easy unfortunately. There are quite a few things to consider before implementing SVG properly in Deno DOM, for example, having an actual XML parser. You can probably get by via silencing that error... Though that is not a solution, and Deno DOM will not distinguish between SVG and HTML elements as it should.

Hopefully soon I can get around to making this work, but at the time being Deno DOM is limited to only processing HTML content.

andreubotella commented 2 years ago

There is some level of support for SVG that deno-dom could have without (before) having to implement a full-on XML parser. For example, the HTML syntax supports embedded SVG, and it will give such elements the SVG namespace. IIRC this is implemented in html5ever, the HTML parser that deno-dom uses, except that currently deno-dom ignores the namespace – once it supports namespaces, supporting SVG embedded in HTML would be trivial to implement. And for simple SVG documents in the XML syntax, parsing them as HTML and doing document.querySelector("svg") might go a long way.