Closed MatTheCat closed 5 years ago
IIRC you'll have to serialize it to transfer it from one jsdom instance to the other.
Oh that makes sense. Will try and update thanks @pkra
You may be able to use importNode()
to make a copy of state.defs
into the new document. E.g., something like
document.body.appendChild(document.importNode(state.defs, true));
might work. I haven't actually tried it, though.
document.body.appendChild(document.importNode(state.defs, true));
throws
TypeError: Failed to execute 'importNode' on 'Document': parameter 1 is not of type 'Node'.
But
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.innerHTML = state.defs.outerHTML
document.body.appendChild(svg)
does the trick.
Thanks for the insight!
I have the following code which processes a HTML file to replace math expressions using MathJax:
console.dir
tells mestate.defs
is aSVGElement
but if I try to append it somewhere I getHow am I supposed to include defs to the DOM?