Skip unsupported nodes even if they have text value #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.