svg import issues

master
Mark MacKay 2021-05-18 11:02:30 -05:00
parent 11e72bf2df
commit 23f5bfd4a7
3 changed files with 9 additions and 2 deletions

View File

@ -147,6 +147,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
if(!node.nodeValue.length) node.parentNode.removeChild(node);
}
if (node.nodeType != 1) return;
var doc = node.ownerDocument;
var parent = node.parentNode;
// can parent ever be null here? I think the root node's parent is the document...
@ -195,7 +196,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
// for the style attribute, rewrite it in terms of XML presentational attributes
if (attrName == "style") {
var props = attr.nodeValue.split(";"),
var props = attr.nodeValue.replace(' ', '').split(";"),
p = props.length;
while(p--) {
var nv = props[p].split(":");
@ -220,7 +221,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
"radialGradient", "textPath", "use"].indexOf(node.nodeName) >= 0)
{
// TODO: we simply check if the first character is a #, is this bullet-proof?
if (href[0] != "#") {
if (href[0] !== "#") {
// remove the attribute (but keep the element)
svgedit.utilities.setHref(node, "");
node.removeAttributeNS(xlinkns, "href");

View File

@ -5786,6 +5786,8 @@ this.setSvgString = function(xmlString) {
try {
// convert string into XML document
var newDoc = svgedit.utilities.text2xml(xmlString);
//var parser = new DOMParser();
//var newDoc = parser.parseFromString(stringContainingXMLSource, "image/svg+xml");
this.prepareSvg(newDoc);

View File

@ -218,6 +218,10 @@ svgedit.utilities.text2xml = function(sXML) {
sXML = sXML.replace(/<(\/?)svg:/g, '<$1').replace('xmlns:svg', 'xmlns');
}
if(sXML.indexOf('xlink:href') >= 0) {
sXML = sXML.replace('xlink:href', 'href');
}
var out;
try{
var dXML = (window.DOMParser)?new DOMParser():new ActiveXObject("Microsoft.XMLDOM");