Skip to content

Commit

Permalink
feat: add support for inlining assets in style attributes
Browse files Browse the repository at this point in the history
Fixes #65
  • Loading branch information
stucox committed Jan 18, 2016
1 parent 14105b5 commit 6c9bba2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var tasks = {
svg: 'svg',
links: 'link[rel=stylesheet]',
styles: 'style',
'style-attrs': '[style]:not(svg *)', // only style attrs in HTML, not SVG
images: 'img',
videos: 'video',
};
Expand Down
15 changes: 15 additions & 0 deletions lib/tasks/style-attrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = resolve;
var debug = require('debug')('inliner');

function resolve(inliner, todo, $) {
debug('start %s style attributes', todo.length);
return todo.map(function links(style) {
var css = $(style).attr('style');
inliner.emit('progress', 'processing inline css');
return inliner.cssImports(inliner.url, css)
.then(inliner.cssImages.bind(inliner, inliner.url))
.then(function then(css) {
$(style).attr('style', css);
});
});
}
1 change: 1 addition & 0 deletions test/fixtures/image-style-attr.result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css image in style attr</title> </head> <body> <div style="background:url(data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=) repeat;"></div> <div style="background:url( &apos;data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=&apos; ) repeat;"></div> <div style="background:url(data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=) repeat;"></div> <div style="background:url(&apos;data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=&apos;) repeat;"></div> </body> </html>
13 changes: 13 additions & 0 deletions test/fixtures/image-style-attr.src.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css image in style attr</title>
</head>
<body>
<div style="background: url(1x1.gif) repeat;"></div>
<div style="background: url( '1x1.gif' ) repeat;"></div>
<div style="background: url(http://localhost:54321/1x1.gif) repeat;"></div>
<div style="background: url('http://localhost:54321/1x1.gif') repeat;"></div>
</body>
</html>

0 comments on commit 6c9bba2

Please sign in to comment.