Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctype persists after svgo, newline char as CRLF #230

Closed
enapupe opened this issue Aug 11, 2014 · 4 comments
Closed

Doctype persists after svgo, newline char as CRLF #230

enapupe opened this issue Aug 11, 2014 · 4 comments

Comments

@enapupe
Copy link

enapupe commented Aug 11, 2014

I'm having two issues with svgo,
first the output is adding (or not removing) the CR char.

The other is the doctype, which is not being removed.

Processed file:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
    <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]><svg xmlns="http://www.w3.org/2000/svg" width="73" height="73" viewBox="-0.8 -0.3 73 73" enable-background="new -0.8 -0.3 73 73"><path fill="#F5DA3F" d="M67 27V0H56v27h-7V15.1L34 27V15.1L19 27V15.1L4.1 27H0v45h72V27h-5zM22 64H11V53h11v11zm0-18H11V35h11v11zm19 18H31V53h10v11zm0-18H31V35h10v11zm20 18H50V53h11v11zm0-18H50V35h11v11z"/></svg>

Original file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
    <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]>
<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
     x="0px" y="0px" width="77px" height="77px" viewBox="-0.9 -0.3 77 77" enable-background="new -0.9 -0.3 77 77"
     xml:space="preserve">
<defs>
</defs>
<circle fill="#B29930" cx="38" cy="38" r="38"/>
<path fill="#F5DA3F" d="M55,31V16h-6v15h-4v-6.7l-8,6.6v-6.6l-8,6.6v-6.6L20.1,31H18v25h40V31H55z M30,51h-6v-5h6V51z M30,42h-6v-6
    h6V42z M41,51h-6v-5h6V51z M41,42h-6v-6h6V42z M52,51h-6v-5h6V51z M52,42h-6v-6h6V42z"/>
</svg>

Expected:

<svg xmlns="http://www.w3.org/2000/svg" width="73" height="73" viewBox="-0.8 -0.3 73 73" enable-background="new -0.8 -0.3 73 73"><path fill="#F5DA3F" d="M67 27V0H56v27h-7V15.1L34 27V15.1L19 27V15.1L4.1 27H0v45h72V27h-5zM22 64H11V53h11v11zm0-18H11V35h11v11zm19 18H31V53h10v11zm0-18H31V35h10v11zm20 18H50V53h11v11zm0-18H50V35h11v11z"/></svg>
@mistakster
Copy link
Contributor

Hello.

Processed file is correct. SVGO doesn’t remove <!DOCTYPE> if there are any ENTITY declarations exist.

@enapupe
Copy link
Author

enapupe commented Aug 26, 2014

So, should I extend the plugin to do it? I don't like these extra bytes.

@mistakster
Copy link
Contributor

If you are 100% sure that you don’t need these entities, you may create additional Grunt task to cut them off using any “text replace” plugin.

I don’t know any straight way to extend existing SVGO plugin. However, you are able to add your own plugin into the processing queue when creating new instance of the SVGO module.

Something like this:

var svgo = new SVGO({
  full: true,
  plugins: [
    'removeXMLProcInst',
    'removeComments',
    'removeMetadata',
    'removeEditorsNSData'
  ]
});

// remove DOCTYPE declaration completely
svgo.config.plugins.push([{
  type: 'perItem',
  active: true,
  fn: function (item) {
    if (item.doctype) {
      return false;
    }
  }
}]);

Please, bear in mind that, it’s just a sample script.

@enapupe
Copy link
Author

enapupe commented Aug 27, 2014

Thanks for that. Thinking a bit more about that bytes, since they are inlined in a css file and served with compression (gzip), I think these bytes won't make a difference..
I'm gonna make a test and if necessary apply the replace.
Many thanks for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants