Skip to content

Commit

Permalink
Merge pull request #54 from hsablonniere/etago
Browse files Browse the repository at this point in the history
fix: inline scripts containing ETAGO properly
  • Loading branch information
remy committed Jul 29, 2015
2 parents 5647244 + e20c0bd commit f4fc886
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function main() {
if (todo.styles.length) {
debug('start %s styles', todo.styles.length);
var stylePromises = todo.styles.map(function links(i, style) {
var css = $(style).html();
var css = $(style).text();
inliner.emit('progress', 'processing inline css');
return inliner.cssImports(url, css)
.then(inliner.cssImages.bind(inliner, url))
Expand All @@ -204,7 +204,7 @@ function main() {
var scriptPromises = todo.scripts.map(function links(i, script) {
var $script = $(script);
var src = $script.attr('src');
var source = $(script).html();
var source = $(script).text();

var promise;

Expand Down Expand Up @@ -239,6 +239,10 @@ function main() {
return promise.then(inliner.uglify.bind(inliner))
.then(function then(res) {
debug('uglify: %s', res);

// remove ETAGO (https://mathiasbynens.be/notes/etago)
res = res.replace(/<\/script/gi, '<\\/script');

$script.text(res);
});
});
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/script-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ var array = [4, 8, 15, 16, 23, 42];

for (var i = 0; i < array.length; i++) {
console.log(array[i]);
}

function surroundWithScriptTag(code) {
return '<script>' + code + '</script>';
}
2 changes: 1 addition & 1 deletion test/fixtures/script-local.result.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>min script</title> </head> <body> <script>for(var array=[4,8,15,16,23,42],i=0;i<array.length;i++)console.log(array[i]);</script> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>min script</title> </head> <body> <script>function surroundWithScriptTag(r){return"<script>"+r+"<\/script>"}for(var array=[4,8,15,16,23,42],i=0;i<array.length;i++)console.log(array[i]);</script> </body> </html>

0 comments on commit f4fc886

Please sign in to comment.