Closed waruyama closed 6 years ago
A style element can contain the style data either as plain text or as a CDATA section. An approach that works cross-browser can look like this:
var funcIriRegExp = new RegExp('url\\("?#([a-zA-Z][\\w:.-]*)"?\\)', 'g');
...
if (element.tagName == 'style') {
element.textContent = element.textContent.replace(funcIriRegExp, 'url(#$1' + idSuffix + ')');
}
Note that we are using textContent
instead of innerHTML
, because the latter does not work on Internet Explorer.
Fixed in a809111
Some graphics programs like Corel Draw export SVGs with the style embedded into a CDATA section inside a style element. Currently IDs inside style elements are not converted.
Here is an example SVG: