Open skozin opened 6 years ago
Just tested it and it works. Hope that it gets merged soon
This still has issue with the rendering of text. When it goes to the inspectNode function it returns null because of the check of allowed elements
if (!ACCEPTED_SVG_ELEMENTS.includes(node.nodeName)) { return null; }
So i still get no render of text svg elements. A quick fix for this would be
if (!ACCEPTED_SVG_ELEMENTS.includes(node.nodeName) && !(node.parentNode.localName==="text")) { return null; }
I hope this helps someone as I was struggling for 2 hours to understand why i don't get text to render.
@rori4 can you please provide an example of SVG that doesn't render correctly? It will help me fixing this.
please merge this commit early. i have a issue relative it 😓
Why it isn't merged yet? It's causing trouble for bunch of people
This PR fixes #112 and #97. It also removes the code added in #76 to fix #84, as it's no longer needed.
The main cause of both issues is that
inspectNode()
function fails to exclude children of unsupported node types when they have some value. This leads to nodes of type#text
(#84) and#comment
(#97, #112) being included into the resulting document as raw text, which, in turn, produces theRaw text cannot be used outside of a <Text> tag
error.Here's what happens: in the very beginning of
inspectNode()
function, there is a check for inclusion of the node type intoACCEPTED_SVG_ELEMENTS
array. If it's not inside the array,null
is returned. In a loop inside the same function, there is another check that doesn't include child into the resulting array if recursive call toinspectNode()
returnednull
, so nodes of unsupported types get skipped.But, inside the same loop, there is a code that adds child node's value into the children array if the node has
nodeValue
property set. It runs before recursing intoinspectNode()
, so nodes withnodeValue
set get included into resulting array even if their type is not insideACCEPTED_SVG_ELEMENTS
array.This PR fixes the issue by making sure that the check for whether node type is supported runs for all child nodes, regardless of whether they have
nodeValue
set.