diff --git a/app/main/static/js/svg_to_png.js b/app/main/static/js/svg_to_png.js index 93de550..f7764e1 100644 --- a/app/main/static/js/svg_to_png.js +++ b/app/main/static/js/svg_to_png.js @@ -38,9 +38,11 @@ function getSVGString(svgNode) { // Add Parent element Id and Classes to the list selectorTextArr.push('#' + parentElement.id); - for (var c = 0; c < parentElement.classList.length; c++) - if (!contains('.' + parentElement.classList[c], selectorTextArr)) + for (var c = 0; c < parentElement.classList.length; c++){ + if (!contains('.' + parentElement.classList[c], selectorTextArr)){ selectorTextArr.push('.' + parentElement.classList[c]); + } + } // Add Children element Ids and Classes to the list var nodes = parentElement.getElementsByTagName("*"); @@ -50,9 +52,10 @@ function getSVGString(svgNode) { selectorTextArr.push('#' + id); var classes = nodes[i].classList; - for (var c = 0; c < classes.length; c++) + for (var c = 0; c < classes.length; c++){ if (!contains('.' + classes[c], selectorTextArr)) selectorTextArr.push('.' + classes[c]); + } } // Extract CSS Rules @@ -69,8 +72,13 @@ function getSVGString(svgNode) { var cssRules = s.cssRules; for (var r = 0; r < cssRules.length; r++) { - if (contains(cssRules[r].selectorText, selectorTextArr)) - extractedCSSText += cssRules[r].cssText; + var cssRule = cssRules[r] + if (typeof cssRule.selectorText === 'undefined') { + continue; + } + var classFromSelector = '.'+cssRule.selectorText.split('.')[1] + if (contains(classFromSelector, selectorTextArr)) + extractedCSSText += cssRule.cssText; } } -- libgit2 0.21.2