Error occurs in
if (child && child.children.length > 0) and if (child && child.attribs.id) when child lacks a children or attribs attr. This occurs (at least) when child is of type 'text'.
quick fix:
Changing the problematic lines to if (child && child.children && child.children.length > 0) and if (child && child.attribs && child.attribs.id)
Example input:
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<style>
/* The content of the style tag is a text-node, and will cause trouble for the _defs function. */
.myclass {
/* some styling */
}
</style>
</defs>
<circle class="myclass" cx="50" cy="50" r="40"/>
</svg>
Error occurs in
if (child && child.children.length > 0)
andif (child && child.attribs.id)
when child lacks achildren
orattribs
attr. This occurs (at least) whenchild
is of type 'text'.quick fix: Changing the problematic lines to
if (child && child.children && child.children.length > 0)
andif (child && child.attribs && child.attribs.id)
Example input: