@maizzle/framework 4.0.0-alpha.9 → 4.0.2

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 (70) 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 -3
  8. package/package.json +91 -91
  9. package/src/generators/config.js +32 -32
  10. package/src/generators/output/index.js +4 -4
  11. package/src/generators/output/to-disk.js +208 -208
  12. package/src/generators/output/to-string.js +1 -5
  13. package/src/generators/postcss.js +29 -29
  14. package/src/generators/posthtml.js +66 -66
  15. package/src/index.js +17 -17
  16. package/src/transformers/attributeToStyle.js +90 -90
  17. package/src/transformers/baseUrl.js +69 -69
  18. package/src/transformers/extraAttributes.js +26 -26
  19. package/src/transformers/filters/defaultFilters.js +126 -126
  20. package/src/transformers/filters/index.js +55 -55
  21. package/src/transformers/index.js +63 -60
  22. package/src/transformers/inlineCss.js +37 -50
  23. package/src/transformers/markdown.js +19 -19
  24. package/src/transformers/minify.js +21 -21
  25. package/src/transformers/plaintext.js +23 -23
  26. package/src/transformers/posthtmlMso.js +10 -10
  27. package/src/transformers/prettify.js +9 -11
  28. package/src/transformers/preventWidows.js +13 -13
  29. package/src/transformers/removeAttributes.js +17 -17
  30. package/src/transformers/removeInlineBackgroundColor.js +52 -52
  31. package/src/transformers/removeInlineSizes.js +41 -41
  32. package/src/transformers/replaceStrings.js +14 -14
  33. package/src/transformers/safeClassNames.js +24 -24
  34. package/src/transformers/shorthandInlineCSS.js +19 -0
  35. package/src/transformers/sixHex.js +33 -33
  36. package/src/transformers/urlParameters.js +17 -17
  37. package/src/utils/helpers.js +17 -17
  38. package/test/expected/posthtml/component.html +1 -1
  39. package/test/expected/posthtml/extend-template.html +2 -2
  40. package/test/expected/posthtml/fetch.html +5 -5
  41. package/test/expected/posthtml/layout.html +3 -3
  42. package/test/expected/transformers/atimport-in-style.html +12 -13
  43. package/test/expected/transformers/base-url.html +99 -99
  44. package/test/expected/transformers/preserve-transform-css.html +33 -45
  45. package/test/expected/useConfig.html +6 -6
  46. package/test/fixtures/posthtml/component.html +2 -2
  47. package/test/fixtures/posthtml/extend-template.html +7 -7
  48. package/test/fixtures/posthtml/fetch.html +9 -9
  49. package/test/fixtures/posthtml/layout.html +11 -11
  50. package/test/fixtures/transformers/base-url.html +101 -101
  51. package/test/stubs/assets/foo.bar +1 -1
  52. package/test/stubs/breaking/bad.html +5 -5
  53. package/test/stubs/config/config.js +10 -10
  54. package/test/stubs/config/config.maizzle-ci.js +10 -10
  55. package/test/stubs/data.json +14 -14
  56. package/test/stubs/events/before-create.html +1 -1
  57. package/test/stubs/layouts/basic.html +1 -1
  58. package/test/stubs/layouts/full.html +12 -12
  59. package/test/stubs/layouts/template.html +5 -5
  60. package/test/stubs/main.css +5 -5
  61. package/test/stubs/tailwind/content-source.html +1 -1
  62. package/test/stubs/tailwind/tailwind.css +3 -3
  63. package/test/stubs/template.html +10 -10
  64. package/test/test-config.js +19 -19
  65. package/test/test-postcss.js +8 -8
  66. package/test/test-posthtml.js +17 -11
  67. package/test/test-tailwindcss.js +117 -117
  68. package/test/test-todisk.js +1 -1
  69. package/test/test-transformers.js +511 -490
  70. package/xo.config.js +22 -22
@@ -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,60 +1,63 @@
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 applyBaseImageUrl = 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 removeInlinedClasses = require('./removeInlinedSelectors')
18
- const removeInlineBgColor = require('./removeInlineBackgroundColor')
19
-
20
- exports.process = async (html, config) => {
21
- html = await safeClassNames(html, config)
22
- html = await filters(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.withFilters = (html, config) => filters(html, config, true)
49
- exports.addURLParams = (html, config) => addURLParams(html, config, true)
50
- exports.preventWidows = (html, config) => preventWidows(html, config, true)
51
- exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
52
- exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
53
- exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config, true)
54
- exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
55
- exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
56
- exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
57
- exports.applyBaseImageUrl = (html, config) => applyBaseImageUrl(html, config, true)
58
- exports.removeInlinedClasses = (html, config) => removeInlinedClasses(html, config)
59
- exports.removeInlineBgColor = (html, config) => removeInlineBgColor(html, config, true)
60
- exports.applyExtraAttributes = (html, config) => applyExtraAttributes(html, config, true)
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
+ }
@@ -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,13 +1,8 @@
1
1
  /* eslint-disable camelcase */
2
-
3
2
  const pretty = require('pretty')
4
- const {get, merge, isEmpty} = require('lodash')
3
+ const {get, merge, isEmpty, isObject} = require('lodash')
5
4
 
6
5
  module.exports = async (html, config = {}, direct = false) => {
7
- if (get(config, 'prettify') === false) {
8
- return html
9
- }
10
-
11
6
  const defaultConfig = {
12
7
  space_around_combinator: true, // Preserve space around CSS selector combinators
13
8
  newline_between_rules: false, // Remove empty lines between CSS rules
@@ -15,15 +10,18 @@ module.exports = async (html, config = {}, direct = false) => {
15
10
  extra_liners: [] // Don't add extra new line before any tag
16
11
  }
17
12
 
18
- config = direct ? config : merge(defaultConfig, get(config, 'prettify', {}))
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
19
 
20
20
  if (typeof config === 'boolean' && config) {
21
21
  return pretty(html, defaultConfig)
22
22
  }
23
23
 
24
- if (!isEmpty(config)) {
25
- return pretty(html, config)
26
- }
24
+ config = merge(defaultConfig, config)
27
25
 
28
- return html
26
+ return pretty(html, config)
29
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
+ }