juice
juice copied to clipboard
Custom attributes and single quotes aren't converted properly
data-sheets-userformat='{"2":5059,"3":[null,0],"4":[null,2,15389148],"9":1,"10":1,"11":4,"12":0,"15":"Calibri"}'
and
style='font-family: "Times New Roman"'
are converted into:
data-sheets-userformat="{"2":5059,"3":[null,0],"4":[null,2,15389148],"9":1,"10":1,"11":4,"12":0,"15":"Calibri"}"
and
style="font-family: "Times New Roman""
The single quotes '
are converted into double quotes "
, which break the html.
I have a feeling this is happening in one of the dependencies juice uses, but I agree this is a problem. A PR to fix this would be most welcome.
@WayneUong
sanitize the html beforehand: https://github.com/punkave/sanitize-html
e.g.,
before:
after:
This is especially egregious in Chrome. See https://codesandbox.io/s/elated-goodall-d3h8eb?file=/src/index.js.
const app = document.getElementById("app");
app.style.fontFamily = "Segoe UI, Arial, sans-serif";
var juice = require("juice");
var result = juice(`
<style>div{color:red;}</style>
${app.outerHTML}
`);
console.log(result);
This results in a font family of " undefined: SegoeUI" undefined: ,Arial,sans-serif;
.