Skip to content

Commit

Permalink
refactor: add backend delimiters defaults to removeUnusedCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Oct 13, 2022
1 parent 92691ab commit 538a93d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/transformers/index.js
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions 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
Expand All @@ -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
}

0 comments on commit 538a93d

Please sign in to comment.