mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
minifyStyles: preserve CDATA if needed
This commit is contained in:
@ -202,7 +202,8 @@ JS2SVG.prototype.createComment = function(comment) {
|
|||||||
*/
|
*/
|
||||||
JS2SVG.prototype.createCDATA = function(cdata) {
|
JS2SVG.prototype.createCDATA = function(cdata) {
|
||||||
|
|
||||||
return this.config.cdataStart +
|
return this.createIndent() +
|
||||||
|
this.config.cdataStart +
|
||||||
cdata +
|
cdata +
|
||||||
this.config.cdataEnd;
|
this.config.cdataEnd;
|
||||||
|
|
||||||
|
@ -43,10 +43,11 @@ exports.fn = function(item, svgoOptions) {
|
|||||||
|
|
||||||
if(item.elem) {
|
if(item.elem) {
|
||||||
if(item.isElem('style') && !item.isEmpty()) {
|
if(item.isElem('style') && !item.isEmpty()) {
|
||||||
var styleCss = item.content[0].text || item.content[0].cdata || [];
|
var styleCss = item.content[0].text || item.content[0].cdata || [],
|
||||||
|
DATA = styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0 ? 'cdata' : 'text';
|
||||||
if(styleCss.length > 0) {
|
if(styleCss.length > 0) {
|
||||||
var styleCssMinified = minifyCss(styleCss, svgoOptions);
|
var styleCssMinified = minifyCss(styleCss, svgoOptions);
|
||||||
item.content[0].text = styleCssMinified;
|
item.content[0][DATA] = styleCssMinified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
test/plugins/minifyStyles.03.svg
Normal file
17
test/plugins/minifyStyles.03.svg
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
||||||
|
<style>
|
||||||
|
<![CDATA[
|
||||||
|
.st0{ fill:red; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; background-image: url('data:image/svg,<svg width="16" height="16"/>') } @media screen and (max-width: 200px) { .st1 { display: none; } }
|
||||||
|
]]>
|
||||||
|
</style>
|
||||||
|
<rect width="100" height="100" class="st0" style="stroke-width:3; margin-top: 1em; margin-right: 1em; margin-bottom: 1em; margin-left: 1em;"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
@@@
|
||||||
|
|
||||||
|
<svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
||||||
|
<style>
|
||||||
|
<![CDATA[.st0{fill:red;padding:1em;background-image:url('data:image/svg,<svg width="16" height="16"/>')}@media screen and (max-width:200px){.st1{display:none}}]]>
|
||||||
|
</style>
|
||||||
|
<rect width="100" height="100" class="st0" style="stroke-width:3;margin:1em"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 890 B |
Reference in New Issue
Block a user