@maizzle/framework 4.0.0-alpha.8 → 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 (84) hide show
  1. package/.editorconfig +9 -9
  2. package/.github/media/logo-dark.svg +1 -0
  3. package/.github/media/logo-light.svg +1 -0
  4. package/.github/workflows/nodejs.yml +28 -28
  5. package/LICENSE +21 -21
  6. package/README.md +42 -35
  7. package/bin/maizzle +3 -0
  8. package/package.json +91 -87
  9. package/src/commands/serve.js +15 -5
  10. package/src/generators/config.js +32 -32
  11. package/src/generators/output/index.js +4 -4
  12. package/src/generators/output/to-disk.js +208 -208
  13. package/src/generators/output/to-string.js +67 -71
  14. package/src/generators/postcss.js +29 -29
  15. package/src/generators/posthtml.js +66 -66
  16. package/src/generators/tailwindcss.js +116 -116
  17. package/src/index.js +17 -17
  18. package/src/transformers/attributeToStyle.js +90 -90
  19. package/src/transformers/baseUrl.js +69 -45
  20. package/src/transformers/extraAttributes.js +26 -26
  21. package/src/transformers/filters/defaultFilters.js +126 -0
  22. package/src/transformers/{transform.js → filters/index.js} +55 -51
  23. package/src/transformers/index.js +63 -60
  24. package/src/transformers/inlineCss.js +37 -50
  25. package/src/transformers/markdown.js +19 -19
  26. package/src/transformers/minify.js +21 -21
  27. package/src/transformers/plaintext.js +23 -23
  28. package/src/transformers/posthtmlMso.js +10 -10
  29. package/src/transformers/prettify.js +27 -20
  30. package/src/transformers/preventWidows.js +13 -13
  31. package/src/transformers/removeAttributes.js +17 -17
  32. package/src/transformers/removeInlineBackgroundColor.js +52 -52
  33. package/src/transformers/removeInlineSizes.js +41 -41
  34. package/src/transformers/removeInlinedSelectors.js +70 -71
  35. package/src/transformers/removeUnusedCss.js +40 -35
  36. package/src/transformers/replaceStrings.js +14 -14
  37. package/src/transformers/safeClassNames.js +24 -24
  38. package/src/transformers/shorthandInlineCSS.js +19 -0
  39. package/src/transformers/sixHex.js +33 -33
  40. package/src/transformers/urlParameters.js +17 -17
  41. package/src/utils/helpers.js +17 -17
  42. package/test/expected/posthtml/component.html +13 -13
  43. package/test/expected/posthtml/extend-template.html +2 -2
  44. package/test/expected/posthtml/fetch.html +5 -5
  45. package/test/expected/posthtml/layout.html +3 -3
  46. package/test/expected/transformers/atimport-in-style.html +2 -1
  47. package/test/expected/transformers/{base-image-url.html → base-url.html} +18 -2
  48. package/test/expected/transformers/filters.html +81 -0
  49. package/test/expected/transformers/preserve-transform-css.html +12 -3
  50. package/test/expected/useConfig.html +9 -9
  51. package/test/fixtures/basic.html +6 -6
  52. package/test/fixtures/posthtml/component.html +19 -19
  53. package/test/fixtures/posthtml/extend-template.html +7 -7
  54. package/test/fixtures/posthtml/fetch.html +9 -9
  55. package/test/fixtures/posthtml/layout.html +11 -11
  56. package/test/fixtures/transformers/{base-image-url.html → base-url.html} +18 -2
  57. package/test/fixtures/transformers/filters.html +87 -0
  58. package/test/fixtures/useConfig.html +9 -9
  59. package/test/stubs/assets/foo.bar +1 -1
  60. package/test/stubs/breaking/bad.html +5 -5
  61. package/test/stubs/components/component.html +5 -5
  62. package/test/stubs/config/config.js +10 -10
  63. package/test/stubs/config/config.maizzle-ci.js +10 -10
  64. package/test/stubs/data.json +14 -14
  65. package/test/stubs/events/before-create.html +1 -1
  66. package/test/stubs/layouts/basic.html +1 -1
  67. package/test/stubs/layouts/full.html +12 -12
  68. package/test/stubs/layouts/template.html +5 -5
  69. package/test/stubs/main.css +5 -5
  70. package/test/stubs/tailwind/content-source.html +1 -1
  71. package/test/stubs/tailwind/tailwind.css +3 -3
  72. package/test/stubs/template.html +10 -10
  73. package/test/stubs/templates/1.html +1 -1
  74. package/test/stubs/templates/2.test +1 -0
  75. package/test/test-config.js +19 -19
  76. package/test/test-postcss.js +8 -8
  77. package/test/test-posthtml.js +72 -66
  78. package/test/test-tailwindcss.js +117 -117
  79. package/test/test-todisk.js +42 -28
  80. package/test/test-tostring.js +148 -142
  81. package/test/test-transformers.js +78 -46
  82. package/xo.config.js +22 -22
  83. package/test/stubs/templates/2.html +0 -1
  84. package/test/stubs/templates/3.mzl +0 -1
@@ -1,45 +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
- // VML backgrounds need regex because they're inside HTML comments :(
7
- const rewriteVMLs = (html, url) => {
8
- const vImageMatch = html.match(/(<v:image.+)(src=['"]([^'"]+)['"])/)
9
- const vFillMatch = html.match(/(<v:fill.+)(src=['"]([^'"]+)['"])/)
10
-
11
- if (vImageMatch && !isUrl(vImageMatch[3])) {
12
- html = html.replace(vImageMatch[0], `${vImageMatch[1]}src="${url}${vImageMatch[3]}"`)
13
- }
14
-
15
- if (vFillMatch && !isUrl(vFillMatch[3])) {
16
- html = html.replace(vFillMatch[0], `${vFillMatch[1]}src="${url}${vFillMatch[3]}"`)
17
- }
18
-
19
- return html
20
- }
21
-
22
- module.exports = async (html, config = {}, direct = false) => {
23
- const url = direct ? config : get(config, 'baseURL')
24
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
25
-
26
- // `baseUrl` as a string
27
- if (typeof url === 'string' && url.length > 0) {
28
- html = rewriteVMLs(html, url)
29
-
30
- return posthtml([
31
- baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
32
- ])
33
- .process(html, posthtmlOptions)
34
- .then(result => result.html)
35
- }
36
-
37
- // `baseUrl: {}`
38
- if (isObject(url) && !isEmpty(url)) {
39
- html = rewriteVMLs(html, url.url)
40
-
41
- return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
42
- }
43
-
44
- return html
45
- }
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
+ }
@@ -0,0 +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,51 +1,55 @@
1
- const posthtml = require('posthtml')
2
- const {get, omit, has} = require('lodash')
3
- const PostCSS = require('../generators/postcss')
4
- const posthtmlContent = require('posthtml-content')
5
- const Tailwind = require('../generators/tailwindcss')
6
- const safeClassNames = require('posthtml-safe-class-names')
7
-
8
- module.exports = async (html, config = {}, direct = false) => {
9
- const replacements = direct ? config : get(config, 'transform', {})
10
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
11
-
12
- /**
13
- * Compile CSS in <style {post|tailwind}css> tags
14
- */
15
- const maizzleConfig = omit(config, ['build.tailwind.css', 'css'])
16
- const tailwindConfig = get(config, 'build.tailwind.config', 'tailwind.config.js')
17
-
18
- replacements.postcss = css => PostCSS.process(css, maizzleConfig)
19
- replacements.tailwindcss = css => Tailwind.compile(css, html, tailwindConfig, maizzleConfig)
20
-
21
- return posthtml([
22
- styleDataEmbed(),
23
- posthtmlContent(replacements),
24
- safeClassNames()
25
- ])
26
- .process(html, posthtmlOptions)
27
- .then(result => result.html)
28
- }
29
-
30
- /**
31
- * Prevent CSS inlining
32
- *
33
- * Add a `data-embed` attribute to <style> tags that we want to preserve.
34
- * Can be used for HTML email client targeting hacks.
35
- */
36
- const styleDataEmbed = () => tree => {
37
- const process = node => {
38
- if (
39
- node.tag === 'style'
40
- && node.attrs
41
- && (has(node.attrs, 'preserve') || has(node.attrs, 'embed'))) {
42
- node.attrs = {...node.attrs, 'data-embed': true}
43
- node.attrs.preserve = false
44
- node.attrs.embed = false
45
- }
46
-
47
- return node
48
- }
49
-
50
- return tree.walk(process)
51
- }
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,60 +1,63 @@
1
- const inline = require('./inlineCss')
2
- const minify = require('./minify')
3
- const markdown = require('./markdown')
4
- const prettify = require('./prettify')
5
- const ensureSixHEX = require('./sixHex')
6
- const applyBaseImageUrl = require('./baseUrl')
7
- const addURLParams = require('./urlParameters')
8
- const transformContents = require('./transform')
9
- const preventWidows = require('./preventWidows')
10
- const replaceStrings = require('./replaceStrings')
11
- const safeClassNames = require('./safeClassNames')
12
- const removeUnusedCSS = require('./removeUnusedCss')
13
- const removeAttributes = require('./removeAttributes')
14
- const attributeToStyle = require('./attributeToStyle')
15
- const removeInlineSizes = require('./removeInlineSizes')
16
- const applyExtraAttributes = require('./extraAttributes')
17
- const removeInlinedClasses = require('./removeInlinedSelectors')
18
- const removeInlineBgColor = require('./removeInlineBackgroundColor')
19
-
20
- exports.process = async (html, config) => {
21
- html = await safeClassNames(html, config)
22
- html = await transformContents(html, config)
23
- html = await markdown(html, config)
24
- html = await preventWidows(html, config)
25
- html = await attributeToStyle(html, config)
26
- html = await inline(html, config)
27
- html = await removeInlinedClasses(html, config)
28
- html = await removeUnusedCSS(html, config)
29
- html = await removeInlineSizes(html, config)
30
- html = await removeInlineBgColor(html, config)
31
- html = await removeAttributes(html, config)
32
- html = await applyExtraAttributes(html, config)
33
- html = await applyBaseImageUrl(html, config)
34
- html = await addURLParams(html, config)
35
- html = await ensureSixHEX(html, config)
36
- html = await prettify(html, config)
37
- html = await minify(html, config)
38
- html = await replaceStrings(html, config)
39
-
40
- return html
41
- }
42
-
43
- exports.minify = (html, config) => minify(html, config, true)
44
- exports.inlineCSS = (html, config) => inline(html, config, true)
45
- exports.markdown = (html, config) => markdown(html, config, true)
46
- exports.prettify = (html, config) => prettify(html, config, true)
47
- exports.ensureSixHEX = (html, config) => ensureSixHEX(html, config)
48
- exports.addURLParams = (html, config) => addURLParams(html, config, true)
49
- exports.preventWidows = (html, config) => preventWidows(html, config, true)
50
- exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
51
- exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
52
- exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
53
- exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
54
- exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
55
- exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
56
- exports.applyBaseImageUrl = (html, config) => applyBaseImageUrl(html, config, true)
57
- exports.transformContents = (html, config) => transformContents(html, config, true)
58
- exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
59
- exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
60
- exports.removeInlinedClasses = (html, config) => removeInlinedClasses(html, config)
1
+ const inline = require('./inlineCss')
2
+ const minify = require('./minify')
3
+ const filters = require('./filters')
4
+ const markdown = require('./markdown')
5
+ const prettify = require('./prettify')
6
+ const ensureSixHEX = require('./sixHex')
7
+ const applyBaseUrl = require('./baseUrl')
8
+ const addURLParams = require('./urlParameters')
9
+ const preventWidows = require('./preventWidows')
10
+ const replaceStrings = require('./replaceStrings')
11
+ const safeClassNames = require('./safeClassNames')
12
+ const removeUnusedCSS = require('./removeUnusedCss')
13
+ const removeAttributes = require('./removeAttributes')
14
+ const attributeToStyle = require('./attributeToStyle')
15
+ const removeInlineSizes = require('./removeInlineSizes')
16
+ const applyExtraAttributes = require('./extraAttributes')
17
+ const shorthandInlineCSS = require('./shorthandInlineCSS')
18
+ const removeInlinedClasses = require('./removeInlinedSelectors')
19
+ const removeInlineBgColor = require('./removeInlineBackgroundColor')
20
+
21
+ exports.process = async (html, config) => {
22
+ html = await safeClassNames(html, config)
23
+ html = await filters(html, config)
24
+ html = await markdown(html, config)
25
+ html = await preventWidows(html, config)
26
+ html = await attributeToStyle(html, config)
27
+ html = await inline(html, config)
28
+ html = await shorthandInlineCSS(html, config)
29
+ html = await removeInlinedClasses(html, config)
30
+ html = await removeUnusedCSS(html, config)
31
+ html = await removeInlineSizes(html, config)
32
+ html = await removeInlineBgColor(html, config)
33
+ html = await removeAttributes(html, config)
34
+ html = await applyExtraAttributes(html, config)
35
+ html = await applyBaseUrl(html, config)
36
+ html = await addURLParams(html, config)
37
+ html = await ensureSixHEX(html, config)
38
+ html = await prettify(html, config)
39
+ html = await minify(html, config)
40
+ html = await replaceStrings(html, config)
41
+
42
+ return html
43
+ }
44
+
45
+ exports.minify = (html, config) => minify(html, config, true)
46
+ exports.inlineCSS = (html, config) => inline(html, config, true)
47
+ exports.markdown = (html, config) => markdown(html, config, true)
48
+ exports.prettify = (html, config) => prettify(html, config, true)
49
+ exports.ensureSixHEX = (html, config) => ensureSixHEX(html, config)
50
+ exports.withFilters = (html, config) => filters(html, config, true)
51
+ exports.addURLParams = (html, config) => addURLParams(html, config, true)
52
+ exports.preventWidows = (html, config) => preventWidows(html, config, true)
53
+ exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
54
+ exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
55
+ exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
56
+ exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
57
+ exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
58
+ exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
59
+ exports.applyBaseUrl = (html, config) => applyBaseUrl(html, config, true)
60
+ exports.removeInlinedClasses = (html, config) => removeInlinedClasses(html, config)
61
+ exports.shorthandInlineCSS = (html, config) => shorthandInlineCSS(html, config, true)
62
+ exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
63
+ exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
@@ -1,50 +1,37 @@
1
- const juice = require('juice')
2
- const posthtml = require('posthtml')
3
- const {get, isObject, isEmpty} = require('lodash')
4
- const mergeLonghand = require('posthtml-postcss-merge-longhand')
5
-
6
- module.exports = async (html, config = {}, direct = false) => {
7
- if (get(config, 'inlineCSS') === false) {
8
- return html
9
- }
10
-
11
- const options = direct ? config : get(config, 'inlineCSS', {})
12
- const removeStyleTags = get(options, 'removeStyleTags', false)
13
- const css = get(config, 'customCSS', false)
14
-
15
- if (get(config, 'inlineCSS') === true || !isEmpty(options)) {
16
- juice.styleToAttribute = get(options, 'styleToAttribute', {'vertical-align': 'valign'})
17
-
18
- juice.widthElements = get(options, 'applyWidthAttributes', [])
19
- juice.heightElements = get(options, 'applyHeightAttributes', [])
20
-
21
- juice.excludedProperties = ['--tw-shadow']
22
-
23
- if (!isEmpty(options.excludedProperties)) {
24
- juice.excludedProperties.push(...get(options, 'excludedProperties', []))
25
- }
26
-
27
- if (isObject(options.codeBlocks) && !isEmpty(options.codeBlocks)) {
28
- Object.entries(options.codeBlocks).forEach(([k, v]) => {
29
- juice.codeBlocks[k] = v
30
- })
31
- }
32
-
33
- html = css ? juice.inlineContent(html, css, {removeStyleTags}) : juice(html, {removeStyleTags})
34
-
35
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
36
- const mergeLonghandConfig = get(options, 'mergeLonghand', [])
37
-
38
- if (typeof mergeLonghandConfig === 'boolean' && mergeLonghandConfig) {
39
- html = await posthtml([mergeLonghand()]).process(html, posthtmlOptions).then(result => result.html)
40
- }
41
-
42
- if (isObject(mergeLonghandConfig) && !isEmpty(mergeLonghandConfig)) {
43
- html = await posthtml([mergeLonghand({tags: mergeLonghandConfig})]).process(html, posthtmlOptions).then(result => result.html)
44
- }
45
-
46
- return html
47
- }
48
-
49
- return html
50
- }
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
+ }