@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.
- package/.editorconfig +9 -9
- package/.github/media/logo-dark.svg +1 -0
- package/.github/media/logo-light.svg +1 -0
- package/.github/workflows/nodejs.yml +28 -28
- package/LICENSE +21 -21
- package/README.md +42 -35
- package/bin/maizzle +3 -3
- package/package.json +91 -91
- package/src/generators/config.js +32 -32
- package/src/generators/output/index.js +4 -4
- package/src/generators/output/to-disk.js +208 -208
- package/src/generators/output/to-string.js +1 -5
- package/src/generators/postcss.js +29 -29
- package/src/generators/posthtml.js +66 -66
- package/src/index.js +17 -17
- package/src/transformers/attributeToStyle.js +90 -90
- package/src/transformers/baseUrl.js +69 -69
- package/src/transformers/extraAttributes.js +26 -26
- package/src/transformers/filters/defaultFilters.js +126 -126
- package/src/transformers/filters/index.js +55 -55
- package/src/transformers/index.js +63 -60
- package/src/transformers/inlineCss.js +37 -50
- package/src/transformers/markdown.js +19 -19
- package/src/transformers/minify.js +21 -21
- package/src/transformers/plaintext.js +23 -23
- package/src/transformers/posthtmlMso.js +10 -10
- package/src/transformers/prettify.js +9 -11
- package/src/transformers/preventWidows.js +13 -13
- package/src/transformers/removeAttributes.js +17 -17
- package/src/transformers/removeInlineBackgroundColor.js +52 -52
- package/src/transformers/removeInlineSizes.js +41 -41
- package/src/transformers/replaceStrings.js +14 -14
- package/src/transformers/safeClassNames.js +24 -24
- package/src/transformers/shorthandInlineCSS.js +19 -0
- package/src/transformers/sixHex.js +33 -33
- package/src/transformers/urlParameters.js +17 -17
- package/src/utils/helpers.js +17 -17
- package/test/expected/posthtml/component.html +1 -1
- package/test/expected/posthtml/extend-template.html +2 -2
- package/test/expected/posthtml/fetch.html +5 -5
- package/test/expected/posthtml/layout.html +3 -3
- package/test/expected/transformers/atimport-in-style.html +12 -13
- package/test/expected/transformers/base-url.html +99 -99
- package/test/expected/transformers/preserve-transform-css.html +33 -45
- package/test/expected/useConfig.html +6 -6
- package/test/fixtures/posthtml/component.html +2 -2
- package/test/fixtures/posthtml/extend-template.html +7 -7
- package/test/fixtures/posthtml/fetch.html +9 -9
- package/test/fixtures/posthtml/layout.html +11 -11
- package/test/fixtures/transformers/base-url.html +101 -101
- package/test/stubs/assets/foo.bar +1 -1
- package/test/stubs/breaking/bad.html +5 -5
- package/test/stubs/config/config.js +10 -10
- package/test/stubs/config/config.maizzle-ci.js +10 -10
- package/test/stubs/data.json +14 -14
- package/test/stubs/events/before-create.html +1 -1
- package/test/stubs/layouts/basic.html +1 -1
- package/test/stubs/layouts/full.html +12 -12
- package/test/stubs/layouts/template.html +5 -5
- package/test/stubs/main.css +5 -5
- package/test/stubs/tailwind/content-source.html +1 -1
- package/test/stubs/tailwind/tailwind.css +3 -3
- package/test/stubs/template.html +10 -10
- package/test/test-config.js +19 -19
- package/test/test-postcss.js +8 -8
- package/test/test-posthtml.js +17 -11
- package/test/test-tailwindcss.js +117 -117
- package/test/test-todisk.js +1 -1
- package/test/test-transformers.js +511 -490
- 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
|
|
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
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
html = await
|
|
23
|
-
html = await
|
|
24
|
-
html = await
|
|
25
|
-
html = await
|
|
26
|
-
html = await
|
|
27
|
-
html = await
|
|
28
|
-
html = await
|
|
29
|
-
html = await
|
|
30
|
-
html = await
|
|
31
|
-
html = await
|
|
32
|
-
html = await
|
|
33
|
-
html = await
|
|
34
|
-
html = await
|
|
35
|
-
html = await
|
|
36
|
-
html = await
|
|
37
|
-
html = await
|
|
38
|
-
html = await
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
exports.
|
|
46
|
-
exports.
|
|
47
|
-
exports.
|
|
48
|
-
exports.
|
|
49
|
-
exports.
|
|
50
|
-
exports.
|
|
51
|
-
exports.
|
|
52
|
-
exports.
|
|
53
|
-
exports.
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.
|
|
58
|
-
exports.
|
|
59
|
-
exports.
|
|
60
|
-
exports.
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
juice.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
juice.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 :
|
|
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
|
-
|
|
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
|
+
}
|