Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
borodean committed Nov 16, 2014
2 parents f0e2b02 + be3b204 commit 941045f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ module.exports = function (options) {
function resolveDataUrl(assetStr) {
var resolvedPath = resolvePath(assetStr);
var mimeType = mime.lookup(resolvedPath);
var data = base64.encode(fs.readFileSync(resolvedPath));
return 'data:' + mimeType + ';base64,' + data;
if (mimeType === 'image/svg+xml') {
var data = cssesc(fs.readFileSync(resolvedPath).toString());
var encoding = 'utf8';
} else {
data = base64.encode(fs.readFileSync(resolvedPath));
encoding = 'base64';
}
return 'data:' + mimeType + ';' + encoding + ',' + data;
}

function resolvePath(assetStr) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-assets",
"version": "0.9.0",
"version": "0.9.1",
"description": "PostCSS plugin to manage assets",
"author": "Vadim Borodean <[email protected]>",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/alpha/trapezium-single-quotes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/fixtures/alpha/trapezium.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/fixtures/inline.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ body {
background: url('alpha/blank.gif');
background: url( 'alpha/blank.gif' );
background: url('alpha/kateryna.jpg');
background: url('alpha/trapezium.svg');
background: url('alpha/trapezium-single-quotes.svg');
}
2 changes: 2 additions & 0 deletions test/fixtures/inline.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ body {
background: url('data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==');
background: url( 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==' );
background: url('/alpha/kateryna.jpg');
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="160" height="120">\D\A <path fill="#4D4D4D" d="M160 120h-160l40-120h80z"/>\D\A</svg>\D\A');
background: url('data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'160\' height=\'120\'>\D\A <path fill=\'#4D4D4D\' d=\'M160 120h-160l40-120h80z\'/>\D\A</svg>\D\A');
}

0 comments on commit 941045f

Please sign in to comment.