Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: double quotes in table style attributes #269

Merged
merged 2 commits into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ function inlineDocument($, css, options) {
}
}

function extractBackgroundUrl(value) {
return value.indexOf('url(') !== 0
? value
: value.replace(/^url\((["'])?([^"']+)\1\)$/, '$2');
}

function setAttributesOnTableElements(el) {
if (!el.name) { return; }
var elName = el.name.toUpperCase();
Expand All @@ -256,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], 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);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion test/cases/juice-content/table-attr.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@
background-image: url('test.png');
background-color: red;
}

td.double {
background-image: url("test.png");
}

td.single {
background-image: url('test.png');
}

td.none {
background-image: url(test.png);
}
</style>
</head>
<body>
<p>none</p>
<table>
<tr>
<td>
<td class="double">
wide
</td>
<td class="single">
wide
</td>
<td class="none">
wide
</td>
</tr>
Expand Down
10 changes: 8 additions & 2 deletions test/cases/juice-content/table-attr.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
</head>
<body>
<p style="text-align: center; vertical-align: middle;">none</p>
<table style="background-image: url('test.png'); background-color: red;" background="url('test.png')" bgcolor="red">
<table style="background-image: url('test.png'); background-color: red;" background="test.png" bgcolor="red">
<tr>
<td style="text-align: center; vertical-align: middle;" align="center" valign="middle">
<td class="double" style="text-align: center; vertical-align: middle; background-image: url('test.png');" align="center" valign="middle" background="test.png">
wide
</td>
<td class="single" style="text-align: center; vertical-align: middle; background-image: url('test.png');" align="center" valign="middle" background="test.png">
wide
</td>
<td class="none" style="text-align: center; vertical-align: middle; background-image: url(test.png);" align="center" valign="middle" background="test.png">
wide
</td>
</tr>
Expand Down