This commit is contained in:
Ben Zörb 2015-02-17 00:59:53 +01:00
parent fbef227f4e
commit af188afe50
4 changed files with 54 additions and 11 deletions

View File

@ -16,6 +16,8 @@ var UglifyJS = require("uglify-js");
var cave = require('cave');
var reaver = require('reaver');
var cheerio = require('cheerio');
var render = require('dom-serializer');
var parse = require('cheerio/lib/parse');
var CleanCSS = require('clean-css');
var slash = require('slash');
var normalizeNewline = require('normalize-newline');
@ -53,7 +55,7 @@ module.exports = function(html, styles, options) {
// minify if minify option is set
if (o.minify) {
styles = new CleanCSS().minify(styles);
styles = new CleanCSS().minify(styles).styles;
}
// insert inline styles right before first <link rel="stylesheet" />
@ -97,5 +99,9 @@ module.exports = function(html, styles, options) {
'}([\'' + hrefs.join('\',\'') + '\']));\n' +
'</script>\n');
return new Buffer($.html());
var dom = parse($.html());
var markup = render(dom);
return new Buffer(markup);
};

View File

@ -21,20 +21,21 @@
},
"dependencies": {
"cave": "^2.0.0",
"cheerio": "^0.17.0",
"clean-css": "^2.2.12",
"cheerio": "^0.18.0",
"clean-css": "^3.0.10",
"dom-serializer": "^0.1.0",
"normalize-newline": "^1.0.1",
"reaver": "^1.2.0",
"slash": "^1.0.0",
"uglify-js": "^2.4.15"
},
"devDependencies": {
"chai": "~1.8.1",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-watch": "~0.5.3",
"chai": "^2.0.0",
"grunt": "~0.4.1",
"grunt-mocha-cli": "~1.1.0",
"grunt-complexity": "~0.1.3",
"grunt-cli": "~0.1.9"
"grunt-cli": "~0.1.9",
"grunt-complexity": "^0.3.0",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-mocha-cli": "^1.12.0"
}
}

28
test/fixtures/entities.html vendored Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>asd</title>
</head>
<body>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewbox="0 0 563 87.9" enable-background="new 0 0 563 87.9" xml:space="preserve" width="167px" height="26px" fill="#fff">
<g>
<g>
<path d="M137.6,23.6h-15.7v-3.1h34.8v3.1H141v42h-3.3V23.6z"/>
<path d="M173.3,20.5h18.9c5.5,0,10,1.7,12.7,4.4c2.1,2.1,3.4,5.1,3.4,8.4v0.1c0,7.5-5.6,11.8-13.2,12.9L210,65.6h-4.2l-14.4-18.7h-0.1h-14.6v18.7h-3.3V20.5z M191.8,43.9c7.5,0,13.1-3.8,13.1-10.3v-0.1c0-6-4.8-9.8-12.9-9.8h-15.4v20.3H191.8z"/>
<path d="M225.6,46.9V20.5h3.3v26c0,10.6,5.7,16.7,15.3,16.7c9.1,0,15-5.5,15-16.4V20.5h3.3v25.9c0,12.9-7.5,19.8-18.5,19.8C233.2,66.3,225.6,59.5,225.6,46.9z"/>
<path d="M281.6,20.5h32.1v3.1H285v17.7h25.8v3.1H285v18.1h29v3.1h-32.4V20.5z"/>
<path d="M326.1,20.5H337l11.8,31.7l11.8-31.7h10.7L353,65.9h-8.8L326.1,20.5z"/>
<path d="M393.6,20.2h9.1l19.3,45.4h-10.4l-4.1-10.1h-19.1l-4.1,10.1h-10.1L393.6,20.2z M404.1,46.7l-6-14.6l-6,14.6H404.1z"/>
<path d="M433.2,46.3V20.5h9.9V46c0,7.3,3.7,11.1,9.7,11.1c6.1,0,9.7-3.7,9.7-10.8V20.5h9.9V46c0,13.6-7.7,20.3-19.8,20.3C440.6,66.3,433.2,59.5,433.2,46.3z"/>
<path d="M489,20.5h9.9v36h22.5v9H489V20.5z"/>
<path d="M539.3,29.7h-13.7v-9.1H563v9.1h-13.7v35.9h-9.9V29.7z"/>
</g>
<g>
<path d="M63.9,17.6H35.5L22.8,36.5l26.8,26.5l26.8-26.6L63.9,17.6z M60.1,41.1l-0.5,1l-0.4,0.6l-0.7-0.4l-6.7-3.7c-0.6,0.6-1.4,0.9-2.3,0.9c-0.9,0-1.7-0.3-2.3-0.9l-6.7,3.7L40,42.7l-0.4-0.6l-0.5-1l-0.4-0.7l0.7-0.4l6.9-3.8c0,0,0,0,0,0c0-1.3,0.8-2.5,2-3v-7v-0.7H49h1.1h0.7v0.7v7c1.2,0.5,2.1,1.7,2.1,3.1c0,0,0,0,0,0l6.9,3.8l0.7,0.4L60.1,41.1z"/>
<path d="M73.3,0H26.1L0,38.8l49.6,49.1L99,38.8L73.3,0zM49.6,67.8L18.5,37l15.3-22.7h31.9l15,22.6L49.6,67.8z"/>
</g>
</g>
</svg>
</body>
</html>

View File

@ -57,4 +57,12 @@ describe('inline-critical', function() {
done();
});
it('should not strip of svg closing tags', function(done) {
var html = read('test/fixtures/entities.html');
var out = inlineCritical(html, '');
expect(strip(out.toString('utf-8'))).to.be.equal(strip(html));
done();
});
});