diff --git a/src/transformers/index.js b/src/transformers/index.js index 61e38808..b7a840d6 100644 --- a/src/transformers/index.js +++ b/src/transformers/index.js @@ -52,7 +52,7 @@ exports.addURLParams = (html, config) => addURLParams(html, config, true) exports.preventWidows = (html, config) => preventWidows(html, config) exports.replaceStrings = (html, config) => replaceStrings(html, config, true) exports.safeClassNames = (html, config) => safeClassNames(html, config, true) -exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true) +exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config) exports.removeAttributes = (html, config) => removeAttributes(html, config, true) exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true) exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true) diff --git a/src/transformers/removeUnusedCss.js b/src/transformers/removeUnusedCss.js index 531425a6..8d58f80b 100644 --- a/src/transformers/removeUnusedCss.js +++ b/src/transformers/removeUnusedCss.js @@ -1,13 +1,11 @@ const {comb} = require('email-comb') -const {get, isEmpty} = require('lodash') +const {get, merge} = require('lodash') -module.exports = async (html, config = {}, direct = false) => { +module.exports = async (html, config = {}) => { if (get(config, 'removeUnusedCSS') === false) { return html } - const options = direct ? config : get(config, 'removeUnusedCSS', {}) - const safelist = [ '*body*', // Gmail '.gmail*', // Gmail @@ -26,15 +24,17 @@ module.exports = async (html, config = {}, direct = false) => { '.lang*' // Fenced code blocks ] - if (typeof options === 'boolean' && options) { - return comb(html, {whitelist: safelist}).result + const defaultOptions = { + backend: [ + {heads: '{{', tails: '}}'}, + {heads: '{%', tails: '%}'} + ], + whitelist: [...get(config, 'whitelist', []), ...safelist] } - if (!isEmpty(options)) { - options.whitelist = [...get(options, 'whitelist', []), ...safelist] - - return comb(html, options).result - } + const options = typeof config === 'boolean' && config ? + defaultOptions : + merge(defaultOptions, get(config, 'removeUnusedCSS', config)) - return html + return comb(html, options).result }