From 8bfd2d0f31bc9b1b3070a7ff2315c40d9d23eafa Mon Sep 17 00:00:00 2001 From: Martti Laine Date: Mon, 10 Jul 2017 21:34:12 +0300 Subject: [PATCH 1/2] Bugfix: double quotes in table style attributes --- lib/inline.js | 6 +++++- test/cases/juice-content/table-attr.html | 4 ++++ test/cases/juice-content/table-attr.out | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/inline.js b/lib/inline.js index cca5319..fb12515 100644 --- a/lib/inline.js +++ b/lib/inline.js @@ -248,6 +248,10 @@ function inlineDocument($, css, options) { } } + function replaceQuotes(value) { + return value.replace(/"/g, "'"); + } + function setAttributesOnTableElements(el) { if (!el.name) { return; } var elName = el.name.toUpperCase(); @@ -256,7 +260,7 @@ function inlineDocument($, css, options) { if (juiceClient.tableElements.indexOf(elName) > -1) { for (var i in el.styleProps) { if (styleProps.indexOf(el.styleProps[i].prop) > -1) { - $(el).attr(juiceClient.styleToAttribute[el.styleProps[i].prop], el.styleProps[i].value); + $(el).attr(juiceClient.styleToAttribute[el.styleProps[i].prop], replaceQuotes(el.styleProps[i].value)); } } } diff --git a/test/cases/juice-content/table-attr.html b/test/cases/juice-content/table-attr.html index 4612b4b..0aa5be0 100644 --- a/test/cases/juice-content/table-attr.html +++ b/test/cases/juice-content/table-attr.html @@ -10,6 +10,10 @@ background-image: url('test.png'); background-color: red; } + + td { + background-image: url("test.png"); + } diff --git a/test/cases/juice-content/table-attr.out b/test/cases/juice-content/table-attr.out index fdb625c..f1c7872 100644 --- a/test/cases/juice-content/table-attr.out +++ b/test/cases/juice-content/table-attr.out @@ -6,7 +6,7 @@

none

- From 8d9af4e4e339422ebb7606bb213e3f3428780c1a Mon Sep 17 00:00:00 2001 From: Martti Laine Date: Thu, 13 Jul 2017 00:10:31 +0300 Subject: [PATCH 2/2] Extract image URL from url(test.png) --- lib/inline.js | 13 ++++++++++--- test/cases/juice-content/table-attr.html | 18 ++++++++++++++++-- test/cases/juice-content/table-attr.out | 10 ++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/inline.js b/lib/inline.js index fb12515..066a989 100644 --- a/lib/inline.js +++ b/lib/inline.js @@ -248,8 +248,10 @@ function inlineDocument($, css, options) { } } - function replaceQuotes(value) { - return value.replace(/"/g, "'"); + function extractBackgroundUrl(value) { + return value.indexOf('url(') !== 0 + ? value + : value.replace(/^url\((["'])?([^"']+)\1\)$/, '$2'); } function setAttributesOnTableElements(el) { @@ -260,7 +262,12 @@ function inlineDocument($, css, options) { if (juiceClient.tableElements.indexOf(elName) > -1) { for (var i in el.styleProps) { if (styleProps.indexOf(el.styleProps[i].prop) > -1) { - $(el).attr(juiceClient.styleToAttribute[el.styleProps[i].prop], replaceQuotes(el.styleProps[i].value)); + var prop = juiceClient.styleToAttribute[el.styleProps[i].prop]; + var value = el.styleProps[i].value; + if (prop === 'background') { + value = extractBackgroundUrl(value) + } + $(el).attr(prop, value); } } } diff --git a/test/cases/juice-content/table-attr.html b/test/cases/juice-content/table-attr.html index 0aa5be0..a723dca 100644 --- a/test/cases/juice-content/table-attr.html +++ b/test/cases/juice-content/table-attr.html @@ -11,16 +11,30 @@ background-color: red; } - td { + td.double { background-image: url("test.png"); } + + td.single { + background-image: url('test.png'); + } + + td.none { + background-image: url(test.png); + }

none

+ wide
- + + diff --git a/test/cases/juice-content/table-attr.out b/test/cases/juice-content/table-attr.out index f1c7872..6bb2e58 100644 --- a/test/cases/juice-content/table-attr.out +++ b/test/cases/juice-content/table-attr.out @@ -4,9 +4,15 @@

none

-
+ + wide + + wide + wide
+
- + +
+ + wide + + wide + wide