@maizzle/framework 4.0.0-alpha.7 → 4.0.0

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 (65) hide show
  1. package/.github/media/logo-dark.svg +1 -0
  2. package/.github/media/logo-light.svg +1 -0
  3. package/.github/workflows/nodejs.yml +1 -1
  4. package/README.md +42 -35
  5. package/bin/maizzle +3 -0
  6. package/package.json +12 -7
  7. package/src/commands/serve.js +31 -18
  8. package/src/generators/output/to-string.js +2 -6
  9. package/src/generators/postcss.js +29 -0
  10. package/src/generators/posthtml.js +66 -61
  11. package/src/generators/tailwindcss.js +1 -1
  12. package/src/index.js +17 -13
  13. package/src/transformers/baseUrl.js +33 -9
  14. package/src/transformers/filters/defaultFilters.js +126 -0
  15. package/src/transformers/filters/index.js +55 -0
  16. package/src/transformers/index.js +15 -9
  17. package/src/transformers/inlineCss.js +1 -14
  18. package/src/transformers/minify.js +1 -1
  19. package/src/transformers/prettify.js +16 -9
  20. package/src/transformers/removeInlineBackgroundColor.js +1 -1
  21. package/src/transformers/removeInlinedSelectors.js +70 -0
  22. package/src/transformers/removeUnusedCss.js +40 -20
  23. package/src/transformers/shorthandInlineCSS.js +19 -0
  24. package/src/transformers/sixHex.js +24 -1
  25. package/test/expected/posthtml/component.html +13 -0
  26. package/test/expected/{inheritance.html → posthtml/extend-template.html} +2 -2
  27. package/test/expected/posthtml/fetch.html +5 -0
  28. package/test/expected/posthtml/layout.html +3 -0
  29. package/test/expected/transformers/atimport-in-style.html +15 -0
  30. package/test/expected/transformers/{base-image-url.html → base-url.html} +18 -2
  31. package/test/expected/transformers/filters.html +81 -0
  32. package/test/expected/transformers/preserve-transform-css.html +36 -0
  33. package/test/expected/useConfig.html +9 -9
  34. package/test/fixtures/basic.html +6 -6
  35. package/test/fixtures/posthtml/component.html +19 -0
  36. package/test/fixtures/{inheritance.html → posthtml/extend-template.html} +7 -7
  37. package/test/fixtures/posthtml/fetch.html +9 -0
  38. package/test/fixtures/posthtml/layout.html +11 -0
  39. package/test/fixtures/transformers/atimport-in-style.html +11 -0
  40. package/test/fixtures/transformers/{base-image-url.html → base-url.html} +18 -2
  41. package/test/fixtures/transformers/filters.html +87 -0
  42. package/test/fixtures/transformers/preserve-transform-css.html +25 -0
  43. package/test/fixtures/useConfig.html +9 -9
  44. package/test/stubs/components/component.html +5 -0
  45. package/test/stubs/data.json +14 -0
  46. package/test/stubs/layouts/basic.html +1 -0
  47. package/test/stubs/{layout.html → layouts/full.html} +0 -0
  48. package/test/stubs/{layout-basic.html → layouts/template.html} +5 -5
  49. package/test/stubs/post.css +6 -0
  50. package/test/stubs/tailwind/{preserve.html → content-source.html} +0 -0
  51. package/test/stubs/tailwind/tailwind.css +3 -0
  52. package/test/stubs/template.html +10 -10
  53. package/test/stubs/templates/1.html +1 -1
  54. package/test/stubs/templates/2.test +1 -0
  55. package/test/test-config.js +19 -19
  56. package/test/test-postcss.js +8 -0
  57. package/test/test-posthtml.js +72 -0
  58. package/test/{test-tailwind.js → test-tailwindcss.js} +117 -117
  59. package/test/test-todisk.js +511 -497
  60. package/test/test-tostring.js +32 -16
  61. package/test/test-transformers.js +510 -343
  62. package/src/transformers/transform.js +0 -22
  63. package/test/expected/transformers/transform-postcss.html +0 -19
  64. package/test/stubs/templates/2.html +0 -1
  65. package/test/stubs/templates/3.mzl +0 -1
@@ -0,0 +1,126 @@
1
+ const escapeMap = {
2
+ '&': '&',
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
@@ -0,0 +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,11 +1,11 @@
1
1
  const inline = require('./inlineCss')
2
2
  const minify = require('./minify')
3
+ const filters = require('./filters')
3
4
  const markdown = require('./markdown')
4
5
  const prettify = require('./prettify')
5
6
  const ensureSixHEX = require('./sixHex')
6
- const applyBaseImageUrl = require('./baseUrl')
7
+ const applyBaseUrl = require('./baseUrl')
7
8
  const addURLParams = require('./urlParameters')
8
- const transformContents = require('./transform')
9
9
  const preventWidows = require('./preventWidows')
10
10
  const replaceStrings = require('./replaceStrings')
11
11
  const safeClassNames = require('./safeClassNames')
@@ -14,21 +14,25 @@ const removeAttributes = require('./removeAttributes')
14
14
  const attributeToStyle = require('./attributeToStyle')
15
15
  const removeInlineSizes = require('./removeInlineSizes')
16
16
  const applyExtraAttributes = require('./extraAttributes')
17
+ const shorthandInlineCSS = require('./shorthandInlineCSS')
18
+ const removeInlinedClasses = require('./removeInlinedSelectors')
17
19
  const removeInlineBgColor = require('./removeInlineBackgroundColor')
18
20
 
19
21
  exports.process = async (html, config) => {
20
22
  html = await safeClassNames(html, config)
21
- html = await transformContents(html, config)
23
+ html = await filters(html, config)
22
24
  html = await markdown(html, config)
23
25
  html = await preventWidows(html, config)
24
26
  html = await attributeToStyle(html, config)
25
27
  html = await inline(html, config)
28
+ html = await shorthandInlineCSS(html, config)
29
+ html = await removeInlinedClasses(html, config)
26
30
  html = await removeUnusedCSS(html, config)
27
31
  html = await removeInlineSizes(html, config)
28
32
  html = await removeInlineBgColor(html, config)
29
33
  html = await removeAttributes(html, config)
30
34
  html = await applyExtraAttributes(html, config)
31
- html = await applyBaseImageUrl(html, config)
35
+ html = await applyBaseUrl(html, config)
32
36
  html = await addURLParams(html, config)
33
37
  html = await ensureSixHEX(html, config)
34
38
  html = await prettify(html, config)
@@ -38,20 +42,22 @@ exports.process = async (html, config) => {
38
42
  return html
39
43
  }
40
44
 
41
- exports.inlineCSS = (html, config) => inline(html, config, true)
42
45
  exports.minify = (html, config) => minify(html, config, true)
46
+ exports.inlineCSS = (html, config) => inline(html, config, true)
43
47
  exports.markdown = (html, config) => markdown(html, config, true)
44
48
  exports.prettify = (html, config) => prettify(html, config, true)
45
49
  exports.ensureSixHEX = (html, config) => ensureSixHEX(html, config)
50
+ exports.withFilters = (html, config) => filters(html, config, true)
46
51
  exports.addURLParams = (html, config) => addURLParams(html, config, true)
47
- exports.transformContents = (html, config) => transformContents(html, config, true)
48
52
  exports.preventWidows = (html, config) => preventWidows(html, config, true)
49
53
  exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
50
54
  exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
51
- exports.applyBaseImageUrl = (html, config) => applyBaseImageUrl(html, config, true)
52
55
  exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
53
56
  exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
57
+ exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
54
58
  exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
55
- exports.applyExtraAttributes = (html, config) => applyExtraAttributes(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)
56
62
  exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
57
- exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
63
+ exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
@@ -1,7 +1,5 @@
1
1
  const juice = require('juice')
2
- const posthtml = require('posthtml')
3
2
  const {get, isObject, isEmpty} = require('lodash')
4
- const mergeLonghand = require('posthtml-postcss-merge-longhand')
5
3
 
6
4
  module.exports = async (html, config = {}, direct = false) => {
7
5
  if (get(config, 'inlineCSS') === false) {
@@ -9,7 +7,7 @@ module.exports = async (html, config = {}, direct = false) => {
9
7
  }
10
8
 
11
9
  const options = direct ? config : get(config, 'inlineCSS', {})
12
- const removeStyleTags = get(options, 'removeStyleTags', true)
10
+ const removeStyleTags = get(options, 'removeStyleTags', false)
13
11
  const css = get(config, 'customCSS', false)
14
12
 
15
13
  if (get(config, 'inlineCSS') === true || !isEmpty(options)) {
@@ -32,17 +30,6 @@ module.exports = async (html, config = {}, direct = false) => {
32
30
 
33
31
  html = css ? juice.inlineContent(html, css, {removeStyleTags}) : juice(html, {removeStyleTags})
34
32
 
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
33
  return html
47
34
  }
48
35
 
@@ -1,5 +1,5 @@
1
- const {get, isEmpty} = require('lodash')
2
1
  const {crush} = require('html-crush')
2
+ const {get, isEmpty} = require('lodash')
3
3
 
4
4
  module.exports = async (html, config = {}, direct = false) => {
5
5
  if (get(config, 'minify') === false) {
@@ -1,20 +1,27 @@
1
- const {get, isEmpty} = require('lodash')
1
+ /* eslint-disable camelcase */
2
2
  const pretty = require('pretty')
3
+ const {get, merge, isEmpty, isObject} = require('lodash')
3
4
 
4
5
  module.exports = async (html, config = {}, direct = false) => {
5
- if (get(config, 'prettify') === false) {
6
- return html
6
+ const defaultConfig = {
7
+ space_around_combinator: true, // Preserve space around CSS selector combinators
8
+ newline_between_rules: false, // Remove empty lines between CSS rules
9
+ indent_inner_html: false, // Helps reduce file size
10
+ extra_liners: [] // Don't add extra new line before any tag
7
11
  }
8
12
 
9
- config = direct ? config : get(config, 'prettify', {})
13
+ config = direct ? config : get(config, 'prettify')
10
14
 
11
- if (typeof config === 'boolean' && config) {
12
- return pretty(html)
15
+ // Don't prettify if not explicitly enabled in config
16
+ if (!config || (isObject(config) && isEmpty(config))) {
17
+ return html
13
18
  }
14
19
 
15
- if (!isEmpty(config)) {
16
- return pretty(html, config)
20
+ if (typeof config === 'boolean' && config) {
21
+ return pretty(html, defaultConfig)
17
22
  }
18
23
 
19
- return html
24
+ config = merge(defaultConfig, config)
25
+
26
+ return pretty(html, config)
20
27
  }
@@ -1,5 +1,5 @@
1
- const {get, isEmpty} = require('lodash')
2
1
  const posthtml = require('posthtml')
2
+ const {get, isEmpty} = require('lodash')
3
3
  const parseAttrs = require('posthtml-attrs-parser')
4
4
 
5
5
  module.exports = async (html, config = {}, direct = false) => {
@@ -0,0 +1,70 @@
1
+ const {get, has, remove} = require('lodash')
2
+ const postcss = require('postcss')
3
+ const posthtml = require('posthtml')
4
+ const parseAttrs = require('posthtml-attrs-parser')
5
+ const matchHelper = require('posthtml-match-helper')
6
+
7
+ module.exports = async (html, config = {}) => {
8
+ if (get(config, 'removeInlinedClasses') === false) {
9
+ return html
10
+ }
11
+
12
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
13
+ return posthtml([plugin()]).process(html, posthtmlOptions).then(result => result.html)
14
+ }
15
+
16
+ const plugin = () => tree => {
17
+ const process = node => {
18
+ // For each style tag...
19
+ if (node.tag === 'style') {
20
+ const {root} = postcss().process(node.content)
21
+
22
+ root.walkRules(rule => {
23
+ // Skip media queries and such...
24
+ if (rule.parent.type === 'atrule') {
25
+ return
26
+ }
27
+
28
+ const {selector} = rule
29
+ const prop = get(rule.nodes[0], 'prop')
30
+
31
+ // If we find the selector in the HTML...
32
+ tree.match(matchHelper(selector), n => {
33
+ const parsedAttrs = parseAttrs(n.attrs)
34
+ const classAttr = get(parsedAttrs, 'class', [])
35
+ const styleAttr = get(parsedAttrs, 'style', {})
36
+
37
+ // If the class is in the style attribute (inlined), remove it
38
+ if (has(styleAttr, prop)) {
39
+ // Remove the class attribute
40
+ remove(classAttr, s => selector.includes(s))
41
+
42
+ // Remove the rule in the <style> tag
43
+ rule.remove()
44
+ }
45
+
46
+ /**
47
+ * Remove from <style> selectors that were used to create shorthand declarations
48
+ * like `margin: 0 0 0 16px` (transformed with mergeLonghand when inlining).
49
+ */
50
+ Object.keys(styleAttr).forEach(key => {
51
+ if (prop.includes(key)) {
52
+ rule.remove()
53
+ remove(classAttr, s => selector.includes(s))
54
+ }
55
+ })
56
+
57
+ n.attrs = parsedAttrs.compose()
58
+
59
+ return n
60
+ })
61
+ })
62
+
63
+ node.content = root.toString()
64
+ }
65
+
66
+ return node
67
+ }
68
+
69
+ return tree.walk(process)
70
+ }
@@ -1,20 +1,40 @@
1
- const {get, isEmpty} = require('lodash')
2
- const {comb} = require('email-comb')
3
-
4
- module.exports = async (html, config = {}, direct = false) => {
5
- if (get(config, 'removeUnusedCSS') === false) {
6
- return html
7
- }
8
-
9
- const options = direct ? config : get(config, 'removeUnusedCSS', {})
10
-
11
- if (typeof options === 'boolean' && options) {
12
- return comb(html).result
13
- }
14
-
15
- if (!isEmpty(options)) {
16
- return comb(html, options).result
17
- }
18
-
19
- return html
20
- }
1
+ const {comb} = require('email-comb')
2
+ const {get, isEmpty} = require('lodash')
3
+
4
+ module.exports = async (html, config = {}, direct = false) => {
5
+ if (get(config, 'removeUnusedCSS') === false) {
6
+ return html
7
+ }
8
+
9
+ const options = direct ? config : get(config, 'removeUnusedCSS', {})
10
+
11
+ const safelist = [
12
+ '*body*', // Gmail
13
+ '.gmail*', // Gmail
14
+ '.apple*', // Apple Mail
15
+ '.ios*', // Mail on iOS
16
+ '.ox-*', // Open-Xchange
17
+ '.outlook*', // Outlook.com
18
+ '.ogs*', // Outlook.com
19
+ '.bloop_container', // Airmail
20
+ '.Singleton', // Apple Mail 10
21
+ '.unused', // Notes 8
22
+ '.moz-text-html', // Thunderbird
23
+ '.mail-detail-content', // Comcast, Libero webmail
24
+ '*edo*', // Edison (all)
25
+ '#*', // Freenet uses #msgBody
26
+ '.lang*' // Fenced code blocks
27
+ ]
28
+
29
+ if (typeof options === 'boolean' && options) {
30
+ return comb(html, {whitelist: safelist}).result
31
+ }
32
+
33
+ if (!isEmpty(options)) {
34
+ options.whitelist = [...get(options, 'whitelist', []), ...safelist]
35
+
36
+ return comb(html, options).result
37
+ }
38
+
39
+ return html
40
+ }
@@ -0,0 +1,19 @@
1
+ const posthtml = require('posthtml')
2
+ const {get, isObject, isEmpty} = require('lodash')
3
+ const mergeLonghand = require('posthtml-postcss-merge-longhand')
4
+
5
+ module.exports = async (html, config, direct = false) => {
6
+ config = direct ? (isObject(config) ? config : true) : get(config, 'shorthandInlineCSS', [])
7
+
8
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
9
+
10
+ if (typeof config === 'boolean' && config) {
11
+ html = await posthtml([mergeLonghand()]).process(html, posthtmlOptions).then(result => result.html)
12
+ }
13
+
14
+ if (isObject(config) && !isEmpty(config)) {
15
+ html = await posthtml([mergeLonghand(config)]).process(html, posthtmlOptions).then(result => result.html)
16
+ }
17
+
18
+ return html
19
+ }
@@ -1,4 +1,6 @@
1
1
  const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const parseAttrs = require('posthtml-attrs-parser')
2
4
  const {conv} = require('color-shorthand-hex-to-six-digit')
3
5
 
4
6
  module.exports = async (html, config = {}) => {
@@ -6,5 +8,26 @@ module.exports = async (html, config = {}) => {
6
8
  return html
7
9
  }
8
10
 
9
- return conv(html)
11
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
12
+ return posthtml([sixHex()]).process(html, posthtmlOptions).then(result => result.html)
13
+ }
14
+
15
+ const sixHex = () => tree => {
16
+ const process = node => {
17
+ const attrs = parseAttrs(node.attrs)
18
+
19
+ const targets = ['bgcolor', 'color']
20
+
21
+ targets.forEach(attribute => {
22
+ if (attrs[attribute]) {
23
+ attrs[attribute] = conv(attrs[attribute])
24
+ }
25
+ })
26
+
27
+ node.attrs = attrs.compose()
28
+
29
+ return node
30
+ }
31
+
32
+ return tree.walk(process)
10
33
  }
@@ -0,0 +1,13 @@
1
+ Variable from attribute: Example
2
+
3
+ Variable from locals attribute: bar
4
+
5
+
6
+ Variable from page: maizzle-ci
7
+
8
+ Variable from attribute: Nested component
9
+
10
+ Variable from locals attribute: bar (nested)
11
+
12
+
13
+ Variable from page (nested): maizzle-ci
@@ -1,2 +1,2 @@
1
- Parent
2
- Child in second.html
1
+ Parent
2
+ Child in second.html
@@ -0,0 +1,5 @@
1
+ Leanne Graham
2
+
3
+ Ervin Howell
4
+
5
+ Clementine Bauch
@@ -0,0 +1,3 @@
1
+ Environment: maizzle-ci
2
+
3
+ Front matter variable: Hello
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <style>div {
5
+ margin-top: 1px;
6
+ margin-right: 2px;
7
+ margin-bottom: 3px;
8
+ margin-left: 4px;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <div>test</div>
14
+ </body>
15
+ </html>
@@ -56,13 +56,21 @@
56
56
 
57
57
  <div>
58
58
  <!--[if mso]>
59
- <v:image xmlns:v="urn:schemas-microsoft-com:vml" src="https://example.com/image.jpg" style="600px;height:400px;" />
60
- <v:rect fill="false" stroke="false" style="position:absolute;600px;height:400px;">
59
+ <v:image xmlns:v="urn:schemas-microsoft-com:vml" src="https://example.com/image.jpg" style="width:600px;height:400px;" />
60
+ <v:rect fill="false" stroke="false" style="position:absolute;width:600px;height:400px;">
61
61
  <v:textbox inset="0,0,0,0"><div><![endif]-->
62
62
  <div>test</div>
63
63
  <!--[if mso]></div></v:textbox></v:rect><![endif]-->
64
64
  </div>
65
65
 
66
+ <!--[if mso]>
67
+ <v:image src="https://example.com/image-2.jpg" xmlns:v="urn:schemas-microsoft-com:vml" style="width:600px;height:400px;" />
68
+ <![endif]-->
69
+
70
+ <!--[if mso]>
71
+ <v:image xmlns:v="urn:schemas-microsoft-com:vml" src="https://example.com/image-3.jpg" style="width:600px;height:400px;" />
72
+ <![endif]-->
73
+
66
74
  <table>
67
75
  <tr>
68
76
  <td background="https://example.com/image.png" bgcolor="#7bceeb" width="120" height="92" valign="top">
@@ -79,5 +87,13 @@
79
87
  </td>
80
88
  </tr>
81
89
  </table>
90
+
91
+ <!--[if mso]>
92
+ <v:fill type="tile" src="https://example.com/image.png" color="#7bceeb" />
93
+ <![endif]-->
94
+
95
+ <!--[if mso]>
96
+ <v:fill type="tile" src="https://example.com/image.png" color="#7bceeb" />
97
+ <![endif]-->
82
98
  </body>
83
99
  </html>