@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,19 +1,19 @@
1
- const posthtml = require('posthtml')
2
- const {get, merge} = require('lodash')
3
- const markdown = require('posthtml-markdownit')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- if (get(config, 'markdown') === false) {
7
- return html
8
- }
9
-
10
- const userMarkdownOptions = direct ? config : get(config, 'markdown', {})
11
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
12
- const markdownOptions = merge({markdownit: {html: true}}, userMarkdownOptions)
13
-
14
- return posthtml([
15
- markdown({...markdownOptions})
16
- ])
17
- .process(html, posthtmlOptions)
18
- .then(result => result.html)
19
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, merge} = require('lodash')
3
+ const markdown = require('posthtml-markdownit')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ if (get(config, 'markdown') === false) {
7
+ return html
8
+ }
9
+
10
+ const userMarkdownOptions = direct ? config : get(config, 'markdown', {})
11
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
12
+ const markdownOptions = merge({markdownit: {html: true}}, userMarkdownOptions)
13
+
14
+ return posthtml([
15
+ markdown({...markdownOptions})
16
+ ])
17
+ .process(html, posthtmlOptions)
18
+ .then(result => result.html)
19
+ }
@@ -1,21 +1,21 @@
1
- const {crush} = require('html-crush')
2
- const {get, isEmpty} = require('lodash')
3
-
4
- module.exports = async (html, config = {}, direct = false) => {
5
- if (get(config, 'minify') === false) {
6
- return html
7
- }
8
-
9
- config = direct ? {
10
- lineLengthLimit: 500,
11
- removeIndentations: true,
12
- removeLineBreaks: true,
13
- ...config
14
- } : get(config, 'minify', {})
15
-
16
- if (!isEmpty(config)) {
17
- html = crush(html, {removeLineBreaks: true, ...config}).result
18
- }
19
-
20
- return html
21
- }
1
+ const {crush} = require('html-crush')
2
+ const {get, isEmpty} = require('lodash')
3
+
4
+ module.exports = async (html, config = {}, direct = false) => {
5
+ if (get(config, 'minify') === false) {
6
+ return html
7
+ }
8
+
9
+ config = direct ? {
10
+ lineLengthLimit: 500,
11
+ removeIndentations: true,
12
+ removeLineBreaks: true,
13
+ ...config
14
+ } : get(config, 'minify', {})
15
+
16
+ if (!isEmpty(config)) {
17
+ html = crush(html, {removeLineBreaks: true, ...config}).result
18
+ }
19
+
20
+ return html
21
+ }
@@ -1,23 +1,23 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
-
4
- module.exports = (html, config = {}) => {
5
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
6
-
7
- return posthtml([plaintext()]).process(html, {...posthtmlOptions, sync: true}).html
8
- }
9
-
10
- const plaintext = () => tree => {
11
- const process = node => {
12
- if (node.tag === 'plaintext') {
13
- return {
14
- tag: false,
15
- content: ['']
16
- }
17
- }
18
-
19
- return node
20
- }
21
-
22
- return tree.walk(process)
23
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+
4
+ module.exports = (html, config = {}) => {
5
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
6
+
7
+ return posthtml([plaintext()]).process(html, {...posthtmlOptions, sync: true}).html
8
+ }
9
+
10
+ const plaintext = () => tree => {
11
+ const process = node => {
12
+ if (node.tag === 'plaintext') {
13
+ return {
14
+ tag: false,
15
+ content: ['']
16
+ }
17
+ }
18
+
19
+ return node
20
+ }
21
+
22
+ return tree.walk(process)
23
+ }
@@ -1,10 +1,10 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
- const outlook = require('posthtml-mso')
4
-
5
- module.exports = async (html, config) => {
6
- const outlookOptions = get(config, 'build.posthtml.outlook', {})
7
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
8
-
9
- return posthtml([outlook({...outlookOptions})]).process(html, {...posthtmlOptions}).then(result => result.html)
10
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const outlook = require('posthtml-mso')
4
+
5
+ module.exports = async (html, config) => {
6
+ const outlookOptions = get(config, 'build.posthtml.outlook', {})
7
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
8
+
9
+ return posthtml([outlook({...outlookOptions})]).process(html, {...posthtmlOptions}).then(result => result.html)
10
+ }
@@ -1,27 +1,27 @@
1
- /* eslint-disable camelcase */
2
- const pretty = require('pretty')
3
- const {get, merge, isEmpty, isObject} = require('lodash')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
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
11
- }
12
-
13
- config = direct ? config : get(config, 'prettify')
14
-
15
- // Don't prettify if not explicitly enabled in config
16
- if (!config || (isObject(config) && isEmpty(config))) {
17
- return html
18
- }
19
-
20
- if (typeof config === 'boolean' && config) {
21
- return pretty(html, defaultConfig)
22
- }
23
-
24
- config = merge(defaultConfig, config)
25
-
26
- return pretty(html, config)
27
- }
1
+ /* eslint-disable camelcase */
2
+ const pretty = require('pretty')
3
+ const {get, merge, isEmpty, isObject} = require('lodash')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
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
11
+ }
12
+
13
+ config = direct ? config : get(config, 'prettify')
14
+
15
+ // Don't prettify if not explicitly enabled in config
16
+ if (!config || (isObject(config) && isEmpty(config))) {
17
+ return html
18
+ }
19
+
20
+ if (typeof config === 'boolean' && config) {
21
+ return pretty(html, defaultConfig)
22
+ }
23
+
24
+ config = merge(defaultConfig, config)
25
+
26
+ return pretty(html, config)
27
+ }
@@ -1,13 +1,13 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
- const preventWidows = require('prevent-widows')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
-
8
- if (direct) {
9
- return preventWidows(html)
10
- }
11
-
12
- return posthtml([preventWidows.posthtml()]).process(html, posthtmlOptions).then(result => result.html)
13
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const preventWidows = require('prevent-widows')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
+
8
+ if (direct) {
9
+ return preventWidows(html)
10
+ }
11
+
12
+ return posthtml([preventWidows.posthtml()]).process(html, posthtmlOptions).then(result => result.html)
13
+ }
@@ -1,17 +1,17 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
- const removeAttributes = require('posthtml-remove-attributes')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const attributes = direct ? (Array.isArray(config) ? [...config] : []) : get(config, 'removeAttributes', [])
7
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
8
-
9
- attributes.push({name: 'style'}, {name: 'class'})
10
-
11
- // Allow omitting `value` key when removing empty attributes
12
- attributes.forEach(attr => {
13
- attr.value = attr.value || ''
14
- })
15
-
16
- return posthtml([removeAttributes(attributes)]).process(html, posthtmlOptions).then(result => result.html)
17
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const removeAttributes = require('posthtml-remove-attributes')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const attributes = direct ? (Array.isArray(config) ? [...config] : []) : get(config, 'removeAttributes', [])
7
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
8
+
9
+ attributes.push({name: 'style'}, {name: 'class'})
10
+
11
+ // Allow omitting `value` key when removing empty attributes
12
+ attributes.forEach(attr => {
13
+ attr.value = attr.value || ''
14
+ })
15
+
16
+ return posthtml([removeAttributes(attributes)]).process(html, posthtmlOptions).then(result => result.html)
17
+ }
@@ -1,52 +1,52 @@
1
- const posthtml = require('posthtml')
2
- const {get, isEmpty} = require('lodash')
3
- const parseAttrs = require('posthtml-attrs-parser')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
-
8
- if (isEmpty(config)) {
9
- return posthtml([removeInlineBGColor()]).process(html, posthtmlOptions).then(result => result.html)
10
- }
11
-
12
- if (get(config, 'inlineCSS.preferBgColorAttribute') === true) {
13
- return posthtml([removeInlineBGColor()]).process(html, posthtmlOptions).then(result => result.html)
14
- }
15
-
16
- const tags = direct ? (Array.isArray(config) ? config : false) : get(config, 'inlineCSS.preferBgColorAttribute', false)
17
-
18
- if (Array.isArray(tags)) {
19
- return posthtml([removeInlineBGColor({tags})]).process(html, posthtmlOptions).then(result => result.html)
20
- }
21
-
22
- return html
23
- }
24
-
25
- const removeInlineBGColor = (options = {}) => tree => {
26
- options.tags = options.tags || ['body', 'marquee', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr']
27
-
28
- const process = node => {
29
- if (!options.tags.includes(node.tag)) {
30
- return node
31
- }
32
-
33
- const attrs = parseAttrs(node.attrs, {
34
- rules: {
35
- bgcolor: {
36
- delimiter: /\s+/,
37
- glue: ' '
38
- }
39
- }
40
- })
41
-
42
- if (attrs.style && attrs.style['background-color']) {
43
- attrs.bgcolor = attrs.style['background-color']
44
- delete attrs.style['background-color']
45
- node.attrs = attrs.compose()
46
- }
47
-
48
- return node
49
- }
50
-
51
- return tree.walk(process)
52
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, isEmpty} = require('lodash')
3
+ const parseAttrs = require('posthtml-attrs-parser')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
+
8
+ if (isEmpty(config)) {
9
+ return posthtml([removeInlineBGColor()]).process(html, posthtmlOptions).then(result => result.html)
10
+ }
11
+
12
+ if (get(config, 'inlineCSS.preferBgColorAttribute') === true) {
13
+ return posthtml([removeInlineBGColor()]).process(html, posthtmlOptions).then(result => result.html)
14
+ }
15
+
16
+ const tags = direct ? (Array.isArray(config) ? config : false) : get(config, 'inlineCSS.preferBgColorAttribute', false)
17
+
18
+ if (Array.isArray(tags)) {
19
+ return posthtml([removeInlineBGColor({tags})]).process(html, posthtmlOptions).then(result => result.html)
20
+ }
21
+
22
+ return html
23
+ }
24
+
25
+ const removeInlineBGColor = (options = {}) => tree => {
26
+ options.tags = options.tags || ['body', 'marquee', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr']
27
+
28
+ const process = node => {
29
+ if (!options.tags.includes(node.tag)) {
30
+ return node
31
+ }
32
+
33
+ const attrs = parseAttrs(node.attrs, {
34
+ rules: {
35
+ bgcolor: {
36
+ delimiter: /\s+/,
37
+ glue: ' '
38
+ }
39
+ }
40
+ })
41
+
42
+ if (attrs.style && attrs.style['background-color']) {
43
+ attrs.bgcolor = attrs.style['background-color']
44
+ delete attrs.style['background-color']
45
+ node.attrs = attrs.compose()
46
+ }
47
+
48
+ return node
49
+ }
50
+
51
+ return tree.walk(process)
52
+ }
@@ -1,41 +1,41 @@
1
- const posthtml = require('posthtml')
2
- const {get, isEmpty} = require('lodash')
3
- const parseAttrs = require('posthtml-attrs-parser')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const settings = direct ? config : get(config, 'inlineCSS.keepOnlyAttributeSizes', {})
7
-
8
- if (!isEmpty(settings)) {
9
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
10
- return posthtml([removeInlineSizes(settings)]).process(html, posthtmlOptions).then(result => result.html)
11
- }
12
-
13
- return html
14
- }
15
-
16
- const removeInlineSizes = (mappings = {}) => tree => {
17
- const process = node => {
18
- const attrs = parseAttrs(node.attrs)
19
- const tag = node.tag ? node.tag.toUpperCase() : ''
20
-
21
- Object.entries(mappings).forEach(([attribute, tags]) => {
22
- tags = Object.values(tags)
23
-
24
- if (!tags.includes(tag)) {
25
- return node
26
- }
27
-
28
- tags.forEach(() => {
29
- if (attrs.style) {
30
- delete attrs.style[attribute]
31
- }
32
- })
33
- })
34
-
35
- node.attrs = attrs.compose()
36
-
37
- return node
38
- }
39
-
40
- return tree.walk(process)
41
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, isEmpty} = require('lodash')
3
+ const parseAttrs = require('posthtml-attrs-parser')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const settings = direct ? config : get(config, 'inlineCSS.keepOnlyAttributeSizes', {})
7
+
8
+ if (!isEmpty(settings)) {
9
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
10
+ return posthtml([removeInlineSizes(settings)]).process(html, posthtmlOptions).then(result => result.html)
11
+ }
12
+
13
+ return html
14
+ }
15
+
16
+ const removeInlineSizes = (mappings = {}) => tree => {
17
+ const process = node => {
18
+ const attrs = parseAttrs(node.attrs)
19
+ const tag = node.tag ? node.tag.toUpperCase() : ''
20
+
21
+ Object.entries(mappings).forEach(([attribute, tags]) => {
22
+ tags = Object.values(tags)
23
+
24
+ if (!tags.includes(tag)) {
25
+ return node
26
+ }
27
+
28
+ tags.forEach(() => {
29
+ if (attrs.style) {
30
+ delete attrs.style[attribute]
31
+ }
32
+ })
33
+ })
34
+
35
+ node.attrs = attrs.compose()
36
+
37
+ return node
38
+ }
39
+
40
+ return tree.walk(process)
41
+ }
@@ -1,14 +1,14 @@
1
- const {isEmpty, get} = require('lodash')
2
-
3
- module.exports = async (html, config = {}, direct = false) => {
4
- const replacements = direct ? config : get(config, 'replaceStrings', {})
5
-
6
- if (!isEmpty(replacements)) {
7
- Object.entries(replacements).forEach(([k, v]) => {
8
- const regex = new RegExp(k, 'gi')
9
- html = html.replace(regex, v)
10
- })
11
- }
12
-
13
- return html
14
- }
1
+ const {isEmpty, get} = require('lodash')
2
+
3
+ module.exports = async (html, config = {}, direct = false) => {
4
+ const replacements = direct ? config : get(config, 'replaceStrings', {})
5
+
6
+ if (!isEmpty(replacements)) {
7
+ Object.entries(replacements).forEach(([k, v]) => {
8
+ const regex = new RegExp(k, 'gi')
9
+ html = html.replace(regex, v)
10
+ })
11
+ }
12
+
13
+ return html
14
+ }
@@ -1,24 +1,24 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
- const safeClassNames = require('posthtml-safe-class-names')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const option = get(config, 'safeClassNames')
7
-
8
- if (option === false) {
9
- return html
10
- }
11
-
12
- /*
13
- * Setting it to `true` in the config will run `safeClassNames`
14
- * no matter the environment.
15
- */
16
- if (config.env === 'local' && !option) {
17
- return html
18
- }
19
-
20
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
21
- const replacements = direct ? config : get(config, 'safeClassNames', {})
22
-
23
- return posthtml([safeClassNames({replacements})]).process(html, posthtmlOptions).then(result => result.html)
24
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const safeClassNames = require('posthtml-safe-class-names')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const option = get(config, 'safeClassNames')
7
+
8
+ if (option === false) {
9
+ return html
10
+ }
11
+
12
+ /*
13
+ * Setting it to `true` in the config will run `safeClassNames`
14
+ * no matter the environment.
15
+ */
16
+ if (config.env === 'local' && !option) {
17
+ return html
18
+ }
19
+
20
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
21
+ const replacements = direct ? config : get(config, 'safeClassNames', {})
22
+
23
+ return posthtml([safeClassNames({replacements})]).process(html, posthtmlOptions).then(result => result.html)
24
+ }
@@ -1,19 +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
+ 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,33 +1,33 @@
1
- const {get} = require('lodash')
2
- const posthtml = require('posthtml')
3
- const parseAttrs = require('posthtml-attrs-parser')
4
- const {conv} = require('color-shorthand-hex-to-six-digit')
5
-
6
- module.exports = async (html, config = {}) => {
7
- if (get(config, 'sixHex') === false) {
8
- return html
9
- }
10
-
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)
33
- }
1
+ const {get} = require('lodash')
2
+ const posthtml = require('posthtml')
3
+ const parseAttrs = require('posthtml-attrs-parser')
4
+ const {conv} = require('color-shorthand-hex-to-six-digit')
5
+
6
+ module.exports = async (html, config = {}) => {
7
+ if (get(config, 'sixHex') === false) {
8
+ return html
9
+ }
10
+
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)
33
+ }