@maizzle/framework 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.editorconfig +9 -9
  2. package/.github/workflows/nodejs.yml +28 -28
  3. package/LICENSE +21 -21
  4. package/bin/maizzle +3 -3
  5. package/package.json +2 -2
  6. package/src/generators/config.js +32 -32
  7. package/src/generators/output/index.js +4 -4
  8. package/src/generators/output/to-disk.js +208 -208
  9. package/src/generators/output/to-string.js +67 -67
  10. package/src/generators/postcss.js +29 -29
  11. package/src/generators/posthtml.js +66 -66
  12. package/src/index.js +17 -17
  13. package/src/transformers/attributeToStyle.js +90 -90
  14. package/src/transformers/baseUrl.js +69 -69
  15. package/src/transformers/extraAttributes.js +26 -26
  16. package/src/transformers/filters/defaultFilters.js +126 -126
  17. package/src/transformers/filters/index.js +55 -55
  18. package/src/transformers/inlineCss.js +37 -37
  19. package/src/transformers/markdown.js +19 -19
  20. package/src/transformers/minify.js +21 -21
  21. package/src/transformers/plaintext.js +23 -23
  22. package/src/transformers/posthtmlMso.js +10 -10
  23. package/src/transformers/prettify.js +27 -27
  24. package/src/transformers/preventWidows.js +13 -13
  25. package/src/transformers/removeAttributes.js +17 -17
  26. package/src/transformers/removeInlineBackgroundColor.js +52 -52
  27. package/src/transformers/removeInlineSizes.js +41 -41
  28. package/src/transformers/replaceStrings.js +14 -14
  29. package/src/transformers/safeClassNames.js +24 -24
  30. package/src/transformers/shorthandInlineCSS.js +19 -19
  31. package/src/transformers/sixHex.js +33 -33
  32. package/src/transformers/urlParameters.js +17 -17
  33. package/src/utils/helpers.js +17 -17
  34. package/test/expected/posthtml/extend-template.html +2 -2
  35. package/test/expected/posthtml/fetch.html +5 -5
  36. package/test/expected/posthtml/layout.html +3 -3
  37. package/test/expected/transformers/base-url.html +99 -99
  38. package/test/fixtures/posthtml/extend-template.html +7 -7
  39. package/test/fixtures/posthtml/fetch.html +9 -9
  40. package/test/fixtures/posthtml/layout.html +11 -11
  41. package/test/fixtures/transformers/base-url.html +101 -101
  42. package/test/stubs/assets/foo.bar +1 -1
  43. package/test/stubs/breaking/bad.html +5 -5
  44. package/test/stubs/config/config.js +10 -10
  45. package/test/stubs/config/config.maizzle-ci.js +10 -10
  46. package/test/stubs/data.json +14 -14
  47. package/test/stubs/events/before-create.html +1 -1
  48. package/test/stubs/layouts/basic.html +1 -1
  49. package/test/stubs/layouts/full.html +12 -12
  50. package/test/stubs/layouts/template.html +5 -5
  51. package/test/stubs/main.css +5 -5
  52. package/test/stubs/tailwind/content-source.html +1 -1
  53. package/test/stubs/tailwind/tailwind.css +3 -3
  54. package/test/stubs/template.html +10 -10
  55. package/test/test-posthtml.js +72 -72
  56. package/test/test-todisk.js +511 -511
  57. package/test/test-transformers.js +1 -0
  58. package/xo.config.js +22 -22
@@ -1,69 +1,69 @@
1
- const posthtml = require('posthtml')
2
- const isUrl = require('is-url-superb')
3
- const baseUrl = require('posthtml-base-url')
4
- const {get, isObject, isEmpty} = require('lodash')
5
-
6
- /**
7
- * VML backgrounds must be handled with regex because
8
- * they're inside HTML comments.
9
- */
10
- const rewriteVMLs = (html, url) => {
11
- // Handle <v:image>
12
- const vImageMatches = html.match(/<v:image[^>]+src="?([^"\s]+)"/g)
13
-
14
- if (vImageMatches) {
15
- vImageMatches.forEach(match => {
16
- const vImage = match.match(/<v:image[^>]+src="?([^"\s]+)"/)
17
- const vImageSrc = vImage[1]
18
-
19
- if (!isUrl(vImageSrc)) {
20
- const vImageSrcUrl = url + vImageSrc
21
- const vImageReplace = vImage[0].replace(vImageSrc, vImageSrcUrl)
22
- html = html.replace(vImage[0], vImageReplace)
23
- }
24
- })
25
- }
26
-
27
- // Handle <v:fill>
28
- const vFillMatches = html.match(/<v:fill[^>]+src="?([^"\s]+)"/g)
29
-
30
- if (vFillMatches) {
31
- vFillMatches.forEach(match => {
32
- const vFill = match.match(/<v:fill[^>]+src="?([^"\s]+)"/)
33
- const vFillSrc = vFill[1]
34
-
35
- if (!isUrl(vFillSrc)) {
36
- const vFillSrcUrl = url + vFillSrc
37
- const vFillReplace = vFill[0].replace(vFillSrc, vFillSrcUrl)
38
- html = html.replace(vFill[0], vFillReplace)
39
- }
40
- })
41
- }
42
-
43
- return html
44
- }
45
-
46
- module.exports = async (html, config = {}, direct = false) => {
47
- const url = direct ? config : get(config, 'baseURL')
48
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
49
-
50
- // Handle `baseUrl` as a string
51
- if (typeof url === 'string' && url.length > 0) {
52
- html = rewriteVMLs(html, url)
53
-
54
- return posthtml([
55
- baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
56
- ])
57
- .process(html, posthtmlOptions)
58
- .then(result => result.html)
59
- }
60
-
61
- // Handle `baseUrl` as an object
62
- if (isObject(url) && !isEmpty(url)) {
63
- html = rewriteVMLs(html, url.url)
64
-
65
- return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
66
- }
67
-
68
- return html
69
- }
1
+ const posthtml = require('posthtml')
2
+ const isUrl = require('is-url-superb')
3
+ const baseUrl = require('posthtml-base-url')
4
+ const {get, isObject, isEmpty} = require('lodash')
5
+
6
+ /**
7
+ * VML backgrounds must be handled with regex because
8
+ * they're inside HTML comments.
9
+ */
10
+ const rewriteVMLs = (html, url) => {
11
+ // Handle <v:image>
12
+ const vImageMatches = html.match(/<v:image[^>]+src="?([^"\s]+)"/g)
13
+
14
+ if (vImageMatches) {
15
+ vImageMatches.forEach(match => {
16
+ const vImage = match.match(/<v:image[^>]+src="?([^"\s]+)"/)
17
+ const vImageSrc = vImage[1]
18
+
19
+ if (!isUrl(vImageSrc)) {
20
+ const vImageSrcUrl = url + vImageSrc
21
+ const vImageReplace = vImage[0].replace(vImageSrc, vImageSrcUrl)
22
+ html = html.replace(vImage[0], vImageReplace)
23
+ }
24
+ })
25
+ }
26
+
27
+ // Handle <v:fill>
28
+ const vFillMatches = html.match(/<v:fill[^>]+src="?([^"\s]+)"/g)
29
+
30
+ if (vFillMatches) {
31
+ vFillMatches.forEach(match => {
32
+ const vFill = match.match(/<v:fill[^>]+src="?([^"\s]+)"/)
33
+ const vFillSrc = vFill[1]
34
+
35
+ if (!isUrl(vFillSrc)) {
36
+ const vFillSrcUrl = url + vFillSrc
37
+ const vFillReplace = vFill[0].replace(vFillSrc, vFillSrcUrl)
38
+ html = html.replace(vFill[0], vFillReplace)
39
+ }
40
+ })
41
+ }
42
+
43
+ return html
44
+ }
45
+
46
+ module.exports = async (html, config = {}, direct = false) => {
47
+ const url = direct ? config : get(config, 'baseURL')
48
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
49
+
50
+ // Handle `baseUrl` as a string
51
+ if (typeof url === 'string' && url.length > 0) {
52
+ html = rewriteVMLs(html, url)
53
+
54
+ return posthtml([
55
+ baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
56
+ ])
57
+ .process(html, posthtmlOptions)
58
+ .then(result => result.html)
59
+ }
60
+
61
+ // Handle `baseUrl` as an object
62
+ if (isObject(url) && !isEmpty(url)) {
63
+ html = rewriteVMLs(html, url.url)
64
+
65
+ return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
66
+ }
67
+
68
+ return html
69
+ }
@@ -1,26 +1,26 @@
1
- const posthtml = require('posthtml')
2
- const {get, isObject} = require('lodash')
3
- const addAttributes = require('posthtml-extra-attributes')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- if (get(config, 'extraAttributes') === false) {
7
- return html
8
- }
9
-
10
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
11
-
12
- let attributes = {
13
- table: {
14
- cellpadding: 0,
15
- cellspacing: 0,
16
- role: 'presentation'
17
- },
18
- img: {
19
- alt: ''
20
- }
21
- }
22
-
23
- attributes = direct ? {...attributes, ...config} : (isObject(config.extraAttributes) ? {...attributes, ...config.extraAttributes} : attributes)
24
-
25
- return posthtml([addAttributes({attributes})]).process(html, posthtmlOptions).then(result => result.html)
26
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, isObject} = require('lodash')
3
+ const addAttributes = require('posthtml-extra-attributes')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ if (get(config, 'extraAttributes') === false) {
7
+ return html
8
+ }
9
+
10
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
11
+
12
+ let attributes = {
13
+ table: {
14
+ cellpadding: 0,
15
+ cellspacing: 0,
16
+ role: 'presentation'
17
+ },
18
+ img: {
19
+ alt: ''
20
+ }
21
+ }
22
+
23
+ attributes = direct ? {...attributes, ...config} : (isObject(config.extraAttributes) ? {...attributes, ...config.extraAttributes} : attributes)
24
+
25
+ return posthtml([addAttributes({attributes})]).process(html, posthtmlOptions).then(result => result.html)
26
+ }
@@ -1,126 +1,126 @@
1
- const escapeMap = {
2
- '&': '&amp;',
3
- '<': '&lt;',
4
- '>': '&gt;',
5
- '"': '&#34;',
6
- '\'': '&#39;'
7
- }
8
-
9
- const unescapeMap = {
10
- '&amp;': '&',
11
- '&lt;': '<',
12
- '&gt;': '>',
13
- '&#34;': '"',
14
- '&#39;': '\''
15
- }
16
-
17
- const unescape = string => string.replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m])
18
-
19
- const append = (content, attribute) => content + attribute
20
- const capitalize = content => content.charAt(0).toUpperCase() + content.slice(1)
21
- const ceil = content => Math.ceil(Number.parseFloat(content))
22
- const divide = (content, attribute) => Number.parseFloat(content) / Number.parseFloat(attribute)
23
- const escape = content => content.replace(/["&'<>]/g, m => escapeMap[m])
24
- const escapeOnce = content => escape(unescape(content))
25
- const floor = content => Math.floor(Number.parseFloat(content))
26
- const lowercase = content => content.toLowerCase()
27
- const lstrip = content => content.replace(/^\s+/, '')
28
- const minus = (content, attribute) => Number.parseFloat(content) - Number.parseFloat(attribute)
29
- const modulo = (content, attribute) => Number.parseFloat(content) % Number.parseFloat(attribute)
30
- const multiply = (content, attribute) => Number.parseFloat(content) * Number.parseFloat(attribute)
31
- const newlineToBr = content => content.replace(/\n/g, '<br>')
32
- const plus = (content, attribute) => Number.parseFloat(content) + Number.parseFloat(attribute)
33
- const prepend = (content, attribute) => attribute + content
34
-
35
- const remove = (content, attribute) => {
36
- const regex = new RegExp(attribute, 'g')
37
- return content.replace(regex, '')
38
- }
39
-
40
- const removeFirst = (content, attribute) => content.replace(attribute, '')
41
- const replace = (content, attribute) => {
42
- const [search, replace] = attribute.split('|')
43
- const regex = new RegExp(search, 'g')
44
- return content.replace(regex, replace)
45
- }
46
-
47
- const replaceFirst = (content, attribute) => {
48
- const [search, replace] = attribute.split('|')
49
- return content.replace(search, replace)
50
- }
51
-
52
- const round = content => Math.round(Number.parseFloat(content))
53
- const rstrip = content => content.replace(/\s+$/, '')
54
- const uppercase = content => content.toUpperCase()
55
- const size = content => content.length
56
- const slice = (content, attribute) => {
57
- try {
58
- const [start, end] = attribute.split(',')
59
- return content.slice(start, end)
60
- } catch {
61
- return content.slice(attribute)
62
- }
63
- }
64
-
65
- const stripNewlines = content => content.replace(/\n/g, '')
66
- const trim = content => content.trim()
67
- const truncate = (content, attribute) => {
68
- try {
69
- const [length, omission] = attribute.split(',')
70
- return content.length > Number.parseInt(length, 10) ?
71
- content.slice(0, length) + (omission || '...') :
72
- content
73
- } catch {
74
- const length = Number.parseInt(attribute, 10)
75
- return content.length > length ? content.slice(0, length) + '...' : content
76
- }
77
- }
78
-
79
- const truncateWords = (content, attribute) => {
80
- try {
81
- const [length, omission] = attribute.split(',')
82
- return content.split(' ').slice(0, Number.parseInt(length, 10)).join(' ') + (omission || '...')
83
- } catch {
84
- const length = Number.parseInt(attribute, 10)
85
- return content.split(' ').slice(0, length).join(' ') + '...'
86
- }
87
- }
88
-
89
- // eslint-disable-next-line
90
- const urlDecode = content => content.split('+').map(decodeURIComponent).join(' ')
91
- // eslint-disable-next-line
92
- const urlEncode = content => content.split(' ').map(encodeURIComponent).join('+')
93
-
94
- exports.append = append
95
- exports.capitalize = capitalize
96
- exports.ceil = ceil
97
- exports['divide-by'] = divide
98
- exports.divide = divide
99
- exports.escape = escape
100
- exports['escape-once'] = escapeOnce
101
- exports.floor = floor
102
- exports.lowercase = lowercase
103
- exports.lstrip = lstrip
104
- exports.minus = minus
105
- exports.modulo = modulo
106
- exports.multiply = multiply
107
- exports['newline-to-br'] = newlineToBr
108
- exports.plus = plus
109
- exports.prepend = prepend
110
- exports.remove = remove
111
- exports['remove-first'] = removeFirst
112
- exports.replace = replace
113
- exports['replace-first'] = replaceFirst
114
- exports.round = round
115
- exports.rstrip = rstrip
116
- exports.uppercase = uppercase
117
- exports.size = size
118
- exports.slice = slice
119
- exports.strip = trim
120
- exports['strip-newlines'] = stripNewlines
121
- exports.times = multiply
122
- exports.trim = trim
123
- exports.truncate = truncate
124
- exports['truncate-words'] = truncateWords
125
- exports['url-decode'] = urlDecode
126
- exports['url-encode'] = urlEncode
1
+ const escapeMap = {
2
+ '&': '&amp;',
3
+ '<': '&lt;',
4
+ '>': '&gt;',
5
+ '"': '&#34;',
6
+ '\'': '&#39;'
7
+ }
8
+
9
+ const unescapeMap = {
10
+ '&amp;': '&',
11
+ '&lt;': '<',
12
+ '&gt;': '>',
13
+ '&#34;': '"',
14
+ '&#39;': '\''
15
+ }
16
+
17
+ const unescape = string => string.replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m])
18
+
19
+ const append = (content, attribute) => content + attribute
20
+ const capitalize = content => content.charAt(0).toUpperCase() + content.slice(1)
21
+ const ceil = content => Math.ceil(Number.parseFloat(content))
22
+ const divide = (content, attribute) => Number.parseFloat(content) / Number.parseFloat(attribute)
23
+ const escape = content => content.replace(/["&'<>]/g, m => escapeMap[m])
24
+ const escapeOnce = content => escape(unescape(content))
25
+ const floor = content => Math.floor(Number.parseFloat(content))
26
+ const lowercase = content => content.toLowerCase()
27
+ const lstrip = content => content.replace(/^\s+/, '')
28
+ const minus = (content, attribute) => Number.parseFloat(content) - Number.parseFloat(attribute)
29
+ const modulo = (content, attribute) => Number.parseFloat(content) % Number.parseFloat(attribute)
30
+ const multiply = (content, attribute) => Number.parseFloat(content) * Number.parseFloat(attribute)
31
+ const newlineToBr = content => content.replace(/\n/g, '<br>')
32
+ const plus = (content, attribute) => Number.parseFloat(content) + Number.parseFloat(attribute)
33
+ const prepend = (content, attribute) => attribute + content
34
+
35
+ const remove = (content, attribute) => {
36
+ const regex = new RegExp(attribute, 'g')
37
+ return content.replace(regex, '')
38
+ }
39
+
40
+ const removeFirst = (content, attribute) => content.replace(attribute, '')
41
+ const replace = (content, attribute) => {
42
+ const [search, replace] = attribute.split('|')
43
+ const regex = new RegExp(search, 'g')
44
+ return content.replace(regex, replace)
45
+ }
46
+
47
+ const replaceFirst = (content, attribute) => {
48
+ const [search, replace] = attribute.split('|')
49
+ return content.replace(search, replace)
50
+ }
51
+
52
+ const round = content => Math.round(Number.parseFloat(content))
53
+ const rstrip = content => content.replace(/\s+$/, '')
54
+ const uppercase = content => content.toUpperCase()
55
+ const size = content => content.length
56
+ const slice = (content, attribute) => {
57
+ try {
58
+ const [start, end] = attribute.split(',')
59
+ return content.slice(start, end)
60
+ } catch {
61
+ return content.slice(attribute)
62
+ }
63
+ }
64
+
65
+ const stripNewlines = content => content.replace(/\n/g, '')
66
+ const trim = content => content.trim()
67
+ const truncate = (content, attribute) => {
68
+ try {
69
+ const [length, omission] = attribute.split(',')
70
+ return content.length > Number.parseInt(length, 10) ?
71
+ content.slice(0, length) + (omission || '...') :
72
+ content
73
+ } catch {
74
+ const length = Number.parseInt(attribute, 10)
75
+ return content.length > length ? content.slice(0, length) + '...' : content
76
+ }
77
+ }
78
+
79
+ const truncateWords = (content, attribute) => {
80
+ try {
81
+ const [length, omission] = attribute.split(',')
82
+ return content.split(' ').slice(0, Number.parseInt(length, 10)).join(' ') + (omission || '...')
83
+ } catch {
84
+ const length = Number.parseInt(attribute, 10)
85
+ return content.split(' ').slice(0, length).join(' ') + '...'
86
+ }
87
+ }
88
+
89
+ // eslint-disable-next-line
90
+ const urlDecode = content => content.split('+').map(decodeURIComponent).join(' ')
91
+ // eslint-disable-next-line
92
+ const urlEncode = content => content.split(' ').map(encodeURIComponent).join('+')
93
+
94
+ exports.append = append
95
+ exports.capitalize = capitalize
96
+ exports.ceil = ceil
97
+ exports['divide-by'] = divide
98
+ exports.divide = divide
99
+ exports.escape = escape
100
+ exports['escape-once'] = escapeOnce
101
+ exports.floor = floor
102
+ exports.lowercase = lowercase
103
+ exports.lstrip = lstrip
104
+ exports.minus = minus
105
+ exports.modulo = modulo
106
+ exports.multiply = multiply
107
+ exports['newline-to-br'] = newlineToBr
108
+ exports.plus = plus
109
+ exports.prepend = prepend
110
+ exports.remove = remove
111
+ exports['remove-first'] = removeFirst
112
+ exports.replace = replace
113
+ exports['replace-first'] = replaceFirst
114
+ exports.round = round
115
+ exports.rstrip = rstrip
116
+ exports.uppercase = uppercase
117
+ exports.size = size
118
+ exports.slice = slice
119
+ exports.strip = trim
120
+ exports['strip-newlines'] = stripNewlines
121
+ exports.times = multiply
122
+ exports.trim = trim
123
+ exports.truncate = truncate
124
+ exports['truncate-words'] = truncateWords
125
+ exports['url-decode'] = urlDecode
126
+ exports['url-encode'] = urlEncode
@@ -1,55 +1,55 @@
1
- const posthtml = require('posthtml')
2
- const {get, omit, has, merge} = require('lodash')
3
- const defaultFilters = require('./defaultFilters')
4
- const PostCSS = require('../../generators/postcss')
5
- const posthtmlContent = require('posthtml-content')
6
- const Tailwind = require('../../generators/tailwindcss')
7
- const safeClassNames = require('posthtml-safe-class-names')
8
-
9
- module.exports = async (html, config = {}, direct = false) => {
10
- const filters = direct ?
11
- merge(defaultFilters, config) :
12
- merge(defaultFilters, get(config, 'filters', {}))
13
-
14
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
15
-
16
- /**
17
- * Compile CSS in <style {post|tailwind}css> tags
18
- */
19
- const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
20
- const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
21
-
22
- filters.postcss = css => PostCSS.process(css, maizzleConfig)
23
- filters.tailwindcss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
24
-
25
- return posthtml([
26
- styleDataEmbed(),
27
- posthtmlContent(filters),
28
- safeClassNames()
29
- ])
30
- .process(html, posthtmlOptions)
31
- .then(result => result.html)
32
- }
33
-
34
- /**
35
- * Prevent CSS inlining
36
- *
37
- * Add a `data-embed` attribute to <style> tags that we want to preserve.
38
- * Can be used for HTML email client targeting hacks.
39
- */
40
- const styleDataEmbed = () => tree => {
41
- const process = node => {
42
- if (
43
- node.tag === 'style'
44
- && node.attrs
45
- && (has(node.attrs, 'preserve') || has(node.attrs, 'embed'))) {
46
- node.attrs = {...node.attrs, 'data-embed': true}
47
- node.attrs.preserve = false
48
- node.attrs.embed = false
49
- }
50
-
51
- return node
52
- }
53
-
54
- return tree.walk(process)
55
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, omit, has, merge} = require('lodash')
3
+ const defaultFilters = require('./defaultFilters')
4
+ const PostCSS = require('../../generators/postcss')
5
+ const posthtmlContent = require('posthtml-content')
6
+ const Tailwind = require('../../generators/tailwindcss')
7
+ const safeClassNames = require('posthtml-safe-class-names')
8
+
9
+ module.exports = async (html, config = {}, direct = false) => {
10
+ const filters = direct ?
11
+ merge(defaultFilters, config) :
12
+ merge(defaultFilters, get(config, 'filters', {}))
13
+
14
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
15
+
16
+ /**
17
+ * Compile CSS in <style {post|tailwind}css> tags
18
+ */
19
+ const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
20
+ const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
21
+
22
+ filters.postcss = css => PostCSS.process(css, maizzleConfig)
23
+ filters.tailwindcss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
24
+
25
+ return posthtml([
26
+ styleDataEmbed(),
27
+ posthtmlContent(filters),
28
+ safeClassNames()
29
+ ])
30
+ .process(html, posthtmlOptions)
31
+ .then(result => result.html)
32
+ }
33
+
34
+ /**
35
+ * Prevent CSS inlining
36
+ *
37
+ * Add a `data-embed` attribute to <style> tags that we want to preserve.
38
+ * Can be used for HTML email client targeting hacks.
39
+ */
40
+ const styleDataEmbed = () => tree => {
41
+ const process = node => {
42
+ if (
43
+ node.tag === 'style'
44
+ && node.attrs
45
+ && (has(node.attrs, 'preserve') || has(node.attrs, 'embed'))) {
46
+ node.attrs = {...node.attrs, 'data-embed': true}
47
+ node.attrs.preserve = false
48
+ node.attrs.embed = false
49
+ }
50
+
51
+ return node
52
+ }
53
+
54
+ return tree.walk(process)
55
+ }
@@ -1,37 +1,37 @@
1
- const juice = require('juice')
2
- const {get, isObject, isEmpty} = require('lodash')
3
-
4
- module.exports = async (html, config = {}, direct = false) => {
5
- if (get(config, 'inlineCSS') === false) {
6
- return html
7
- }
8
-
9
- const options = direct ? config : get(config, 'inlineCSS', {})
10
- const removeStyleTags = get(options, 'removeStyleTags', false)
11
- const css = get(config, 'customCSS', false)
12
-
13
- if (get(config, 'inlineCSS') === true || !isEmpty(options)) {
14
- juice.styleToAttribute = get(options, 'styleToAttribute', {'vertical-align': 'valign'})
15
-
16
- juice.widthElements = get(options, 'applyWidthAttributes', [])
17
- juice.heightElements = get(options, 'applyHeightAttributes', [])
18
-
19
- juice.excludedProperties = ['--tw-shadow']
20
-
21
- if (!isEmpty(options.excludedProperties)) {
22
- juice.excludedProperties.push(...get(options, 'excludedProperties', []))
23
- }
24
-
25
- if (isObject(options.codeBlocks) && !isEmpty(options.codeBlocks)) {
26
- Object.entries(options.codeBlocks).forEach(([k, v]) => {
27
- juice.codeBlocks[k] = v
28
- })
29
- }
30
-
31
- html = css ? juice.inlineContent(html, css, {removeStyleTags}) : juice(html, {removeStyleTags})
32
-
33
- return html
34
- }
35
-
36
- return html
37
- }
1
+ const juice = require('juice')
2
+ const {get, isObject, isEmpty} = require('lodash')
3
+
4
+ module.exports = async (html, config = {}, direct = false) => {
5
+ if (get(config, 'inlineCSS') === false) {
6
+ return html
7
+ }
8
+
9
+ const options = direct ? config : get(config, 'inlineCSS', {})
10
+ const removeStyleTags = get(options, 'removeStyleTags', false)
11
+ const css = get(config, 'customCSS', false)
12
+
13
+ if (get(config, 'inlineCSS') === true || !isEmpty(options)) {
14
+ juice.styleToAttribute = get(options, 'styleToAttribute', {'vertical-align': 'valign'})
15
+
16
+ juice.widthElements = get(options, 'applyWidthAttributes', [])
17
+ juice.heightElements = get(options, 'applyHeightAttributes', [])
18
+
19
+ juice.excludedProperties = ['--tw-shadow']
20
+
21
+ if (!isEmpty(options.excludedProperties)) {
22
+ juice.excludedProperties.push(...get(options, 'excludedProperties', []))
23
+ }
24
+
25
+ if (isObject(options.codeBlocks) && !isEmpty(options.codeBlocks)) {
26
+ Object.entries(options.codeBlocks).forEach(([k, v]) => {
27
+ juice.codeBlocks[k] = v
28
+ })
29
+ }
30
+
31
+ html = css ? juice.inlineContent(html, css, {removeStyleTags}) : juice(html, {removeStyleTags})
32
+
33
+ return html
34
+ }
35
+
36
+ return html
37
+ }