b-fuze / deno-dom

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

Namespace support #143

Open StarLederer opened 1 year ago

StarLederer commented 1 year ago

It looks like Namespaces are not currently supported.

Namespaces are not too common but are still sometimes found useful, e.g. when working with SVG, OOXML or other non-HTML XML formats.

Would it be possible to add support for this feature and implement functions such as createAttributeNS, createElementNS, setAttributeNS etc. so that deno-dom can be used in libraries that build and manipulate exotic (or not so much) XML formats?

StarLederer commented 1 year ago

Might be a duplicate of #140 but that issue focuses entirely on CSS while this one entirely on the DOM

rgbkrk commented 1 year ago

Thanks for making the issue. I'm really curious about being able to run plotting libraries server side like this:

import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import * as Plot from "npm:@observablehq/plot"

const document = new DOMParser().parseFromString(
  `<html>
    <body>
      <div id="root" />
    </body>
  </html>`,
  "text/html",
);

Plot.barY(alphabet, {x: "letter", y: "frequency"}).plot({document})

which inevitably needs createElementNS to work for SVG:

Error: createElementNS: "http://www.w3.org/2000/svg" namespace unimplemented
    at HTMLDocument.createElementNS (https://deno.land/x/deno_dom@v0.1.38/src/dom/document.ts:244:13)
    at Element.<anonymous> (file:///Users/kai/Library/Caches/deno/npm/registry.npmjs.org/d3-selection/3.0.0/src/creator.js:16:31)
    at plot (file:///Users/kai/Library/Caches/deno/npm/registry.npmjs.org/@observablehq/plot/0.6.10/src/plot.js:156:30)
    at BarY.plotThis [as plot] (file:///Users/kai/Library/Caches/deno/npm/registry.npmjs.org/@observablehq/plot/0.6.10/src/plot.js:370:10)
    at <anonymous>:12:4: 
b-fuze commented 1 year ago

Might be a duplicate of https://github.com/b-fuze/deno-dom/issues/140 but that issue focuses entirely on CSS while this one entirely on the DOM

No, it's not a duplicate of that issue. But it does coincide with that issue + #73 in general. I want to add XML support which will also require implementing namespaces as well

StarLederer commented 1 year ago

Awesome! Really looking forward to it