@maizzle/framework 4.0.0-alpha.6 → 4.0.0-alpha.9
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/.github/workflows/nodejs.yml +1 -1
- package/bin/maizzle +3 -0
- package/package.json +12 -7
- package/src/commands/serve.js +36 -19
- package/src/generators/output/to-string.js +71 -71
- package/src/generators/postcss.js +29 -0
- package/src/generators/posthtml.js +66 -61
- package/src/generators/tailwindcss.js +1 -1
- package/src/index.js +17 -13
- package/src/transformers/baseUrl.js +33 -9
- package/src/transformers/filters/defaultFilters.js +126 -0
- package/src/transformers/filters/index.js +55 -0
- package/src/transformers/index.js +60 -57
- package/src/transformers/inlineCss.js +1 -1
- package/src/transformers/minify.js +1 -1
- package/src/transformers/prettify.js +29 -20
- package/src/transformers/removeInlineBackgroundColor.js +1 -1
- package/src/transformers/removeInlinedSelectors.js +70 -0
- package/src/transformers/removeUnusedCss.js +40 -20
- package/src/transformers/sixHex.js +24 -1
- package/test/expected/posthtml/component.html +13 -0
- package/test/expected/{inheritance.html → posthtml/extend-template.html} +2 -2
- package/test/expected/posthtml/fetch.html +5 -0
- package/test/expected/posthtml/layout.html +3 -0
- package/test/expected/transformers/atimport-in-style.html +16 -0
- package/test/expected/transformers/{base-image-url.html → base-url.html} +18 -2
- package/test/expected/transformers/filters.html +81 -0
- package/test/expected/transformers/preserve-transform-css.html +48 -0
- package/test/expected/useConfig.html +9 -9
- package/test/fixtures/basic.html +6 -6
- package/test/fixtures/posthtml/component.html +19 -0
- package/test/fixtures/{inheritance.html → posthtml/extend-template.html} +7 -7
- package/test/fixtures/posthtml/fetch.html +9 -0
- package/test/fixtures/posthtml/layout.html +11 -0
- package/test/fixtures/transformers/atimport-in-style.html +11 -0
- package/test/fixtures/transformers/{base-image-url.html → base-url.html} +18 -2
- package/test/fixtures/transformers/filters.html +87 -0
- package/test/fixtures/transformers/preserve-transform-css.html +25 -0
- package/test/fixtures/useConfig.html +9 -9
- package/test/stubs/components/component.html +5 -0
- package/test/stubs/data.json +14 -0
- package/test/stubs/layouts/basic.html +1 -0
- package/test/stubs/{layout.html → layouts/full.html} +0 -0
- package/test/stubs/{layout-basic.html → layouts/template.html} +5 -5
- package/test/stubs/post.css +6 -0
- package/test/stubs/tailwind/{preserve.html → content-source.html} +0 -0
- package/test/stubs/tailwind/tailwind.css +3 -0
- package/test/stubs/template.html +10 -10
- package/test/stubs/templates/1.html +1 -1
- package/test/stubs/templates/2.test +1 -0
- package/test/test-postcss.js +8 -0
- package/test/test-posthtml.js +66 -0
- package/test/{test-tailwind.js → test-tailwindcss.js} +4 -4
- package/test/test-todisk.js +43 -29
- package/test/test-tostring.js +32 -16
- package/test/test-transformers.js +173 -26
- package/src/transformers/transform.js +0 -22
- package/test/expected/transformers/transform-postcss.html +0 -19
- package/test/stubs/templates/2.html +0 -1
- package/test/stubs/templates/3.mzl +0 -1
package/bin/maizzle
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maizzle/framework",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.9",
|
|
4
4
|
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"maizzle": "bin/maizzle"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "https://github.com/maizzle/framework.git"
|
|
@@ -33,10 +36,11 @@
|
|
|
33
36
|
"release": "np"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
39
|
+
"@maizzle/cli": "^1.4.0",
|
|
36
40
|
"autoprefixer": "^10.4.0",
|
|
37
41
|
"browser-sync": "^2.26.13",
|
|
38
42
|
"color-shorthand-hex-to-six-digit": "^3.0.2",
|
|
39
|
-
"email-comb": "^5.
|
|
43
|
+
"email-comb": "^5.2.0",
|
|
40
44
|
"front-matter": "^4.0.0",
|
|
41
45
|
"fs-extra": "^10.0.0",
|
|
42
46
|
"glob-promise": "^4.1.0",
|
|
@@ -51,17 +55,18 @@
|
|
|
51
55
|
"posthtml": "^0.16.6",
|
|
52
56
|
"posthtml-attrs-parser": "^0.1.1",
|
|
53
57
|
"posthtml-base-url": "^1.0.1",
|
|
54
|
-
"posthtml-content": "^0.0
|
|
58
|
+
"posthtml-content": "^0.1.0",
|
|
55
59
|
"posthtml-expressions": "^1.8.1",
|
|
56
60
|
"posthtml-extend": "^0.6.0",
|
|
57
61
|
"posthtml-extra-attributes": "^1.0.0",
|
|
58
|
-
"posthtml-fetch": "^2.
|
|
62
|
+
"posthtml-fetch": "^2.2.0",
|
|
59
63
|
"posthtml-markdownit": "^1.3.0",
|
|
60
|
-
"posthtml-
|
|
64
|
+
"posthtml-match-helper": "^1.0.3",
|
|
65
|
+
"posthtml-modules": "^0.9.0",
|
|
61
66
|
"posthtml-mso": "^1.0.4",
|
|
62
67
|
"posthtml-postcss-merge-longhand": "^1.0.2",
|
|
63
68
|
"posthtml-remove-attributes": "^1.0.0",
|
|
64
|
-
"posthtml-safe-class-names": "^1.0.
|
|
69
|
+
"posthtml-safe-class-names": "^1.0.8",
|
|
65
70
|
"posthtml-url-parameters": "^1.0.4",
|
|
66
71
|
"pretty": "^2.0.0",
|
|
67
72
|
"prevent-widows": "^1.0.2",
|
|
@@ -76,7 +81,7 @@
|
|
|
76
81
|
"xo": "0.39.1"
|
|
77
82
|
},
|
|
78
83
|
"engines": {
|
|
79
|
-
"node": ">=
|
|
84
|
+
"node": ">=14.0.0"
|
|
80
85
|
},
|
|
81
86
|
"ava": {
|
|
82
87
|
"files": [
|
package/src/commands/serve.js
CHANGED
|
@@ -41,13 +41,27 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
41
41
|
const globalPaths = [
|
|
42
42
|
'src/**',
|
|
43
43
|
get(config, 'build.tailwind.config', 'tailwind.config.js'),
|
|
44
|
-
|
|
44
|
+
...new Set(get(config, 'build.browsersync.watch', []))
|
|
45
45
|
]
|
|
46
46
|
|
|
47
47
|
// Watch for Template file changes
|
|
48
48
|
browsersync()
|
|
49
49
|
.watch(templatePaths)
|
|
50
50
|
.on('change', async file => {
|
|
51
|
+
if (config.events && typeof config.events.beforeCreate === 'function') {
|
|
52
|
+
await config.events.beforeCreate(config)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Don't render if file type is not configured
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
const filetypes = templates.reduce((acc, template) => {
|
|
58
|
+
return [...acc, ...get(template, 'filetypes', ['html'])]
|
|
59
|
+
}, [])
|
|
60
|
+
|
|
61
|
+
if (!filetypes.includes(path.extname(file).slice(1))) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
51
65
|
if (get(config, 'build.console.clear')) {
|
|
52
66
|
clearConsole()
|
|
53
67
|
}
|
|
@@ -58,10 +72,6 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
58
72
|
|
|
59
73
|
file = file.replace(/\\/g, '/')
|
|
60
74
|
|
|
61
|
-
if (config.events && typeof config.events.beforeCreate === 'function') {
|
|
62
|
-
await config.events.beforeCreate(config)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
75
|
const renderOptions = {
|
|
66
76
|
maizzle: config,
|
|
67
77
|
...config.events
|
|
@@ -72,19 +82,23 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
72
82
|
renderOptions
|
|
73
83
|
)
|
|
74
84
|
.then(async ({html, config}) => {
|
|
85
|
+
let source = ''
|
|
75
86
|
let dest = ''
|
|
76
87
|
let ext = ''
|
|
77
88
|
|
|
78
89
|
if (Array.isArray(config.build.templates)) {
|
|
79
90
|
const match = config.build.templates.find(template => template.source === path.parse(file).dir)
|
|
91
|
+
source = get(match, 'source')
|
|
80
92
|
dest = get(match, 'destination.path', 'build_local')
|
|
81
93
|
ext = get(match, 'destination.ext', 'html')
|
|
82
94
|
} else if (isObject(config.build.templates)) {
|
|
95
|
+
source = get(config, 'build.templates.source')
|
|
83
96
|
dest = get(config, 'build.templates.destination.path', 'build_local')
|
|
84
97
|
ext = get(config, 'build.templates.destination.ext', 'html')
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
const
|
|
100
|
+
const fileDir = path.parse(file).dir.replace(source, '')
|
|
101
|
+
const finalDestination = path.join(dest, fileDir, `${path.parse(file).name}.${ext}`)
|
|
88
102
|
|
|
89
103
|
await fs.outputFile(config.permalink || finalDestination, html)
|
|
90
104
|
})
|
|
@@ -117,19 +131,22 @@ const serve = async (env = 'local', config = {}) => {
|
|
|
117
131
|
|
|
118
132
|
// Initialize Browsersync
|
|
119
133
|
browsersync()
|
|
120
|
-
.init(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
.init(
|
|
135
|
+
merge(
|
|
136
|
+
{
|
|
137
|
+
notify: false,
|
|
138
|
+
open: false,
|
|
139
|
+
port: 3000,
|
|
140
|
+
server: {
|
|
141
|
+
baseDir,
|
|
142
|
+
directory: true
|
|
143
|
+
},
|
|
144
|
+
tunnel: false,
|
|
145
|
+
ui: {port: 3001},
|
|
146
|
+
logFileChanges: false
|
|
147
|
+
},
|
|
148
|
+
get(config, 'build.browsersync', {})
|
|
149
|
+
), () => {})
|
|
133
150
|
} catch (error) {
|
|
134
151
|
spinner.fail(error)
|
|
135
152
|
throw error
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
const fm = require('front-matter')
|
|
2
|
-
const {get, merge} = require('lodash')
|
|
3
|
-
const posthtml = require('../posthtml')
|
|
4
|
-
const Tailwind = require('../tailwindcss')
|
|
5
|
-
const Transformers = require('../../transformers')
|
|
6
|
-
const posthtmlMSO = require('../../transformers/posthtmlMso')
|
|
7
|
-
const Config = require('../config')
|
|
8
|
-
|
|
9
|
-
module.exports = async (html, options) => {
|
|
10
|
-
process.env.NODE_ENV = get(options, 'maizzle.env', 'local')
|
|
11
|
-
|
|
12
|
-
if (typeof html !== 'string') {
|
|
13
|
-
throw new TypeError(`first argument must be an HTML string, received ${html}`)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (html.length === 0) {
|
|
17
|
-
throw new RangeError('received empty string')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const fileConfig = await Config.getMerged(process.env.NODE_ENV)
|
|
21
|
-
|
|
22
|
-
let config = merge(fileConfig, get(options, 'maizzle', {}))
|
|
23
|
-
|
|
24
|
-
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
25
|
-
const cssString = get(options, 'tailwind.css', '
|
|
26
|
-
|
|
27
|
-
let {frontmatter} = fm(html)
|
|
28
|
-
|
|
29
|
-
if (frontmatter) {
|
|
30
|
-
frontmatter = await posthtml(frontmatter, config)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
|
|
34
|
-
|
|
35
|
-
config = merge({applyTransformers: true}, config, fm(html).attributes)
|
|
36
|
-
|
|
37
|
-
if (typeof get(options, 'tailwind.compiled') === 'string') {
|
|
38
|
-
config.css = options.tailwind.compiled
|
|
39
|
-
} else {
|
|
40
|
-
config.css = await Tailwind.compile(cssString, html, tailwindConfig, config)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (options && typeof options.beforeRender === 'function') {
|
|
44
|
-
html = await options.beforeRender(html, config)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
html = await posthtml(html, config)
|
|
48
|
-
|
|
49
|
-
while (Object.keys(fm(html).attributes).length > 0) {
|
|
50
|
-
html = fm(html).body
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (options && typeof options.afterRender === 'function') {
|
|
54
|
-
html = await options.afterRender(html, config)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (config.applyTransformers) {
|
|
58
|
-
html = await Transformers.process(html, config)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (options && typeof options.afterTransformers === 'function') {
|
|
62
|
-
html = await options.afterTransformers(html, config)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
html = await posthtmlMSO(html, config)
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
html,
|
|
69
|
-
config
|
|
70
|
-
}
|
|
71
|
-
}
|
|
1
|
+
const fm = require('front-matter')
|
|
2
|
+
const {get, merge} = require('lodash')
|
|
3
|
+
const posthtml = require('../posthtml')
|
|
4
|
+
const Tailwind = require('../tailwindcss')
|
|
5
|
+
const Transformers = require('../../transformers')
|
|
6
|
+
const posthtmlMSO = require('../../transformers/posthtmlMso')
|
|
7
|
+
const Config = require('../config')
|
|
8
|
+
|
|
9
|
+
module.exports = async (html, options) => {
|
|
10
|
+
process.env.NODE_ENV = get(options, 'maizzle.env', 'local')
|
|
11
|
+
|
|
12
|
+
if (typeof html !== 'string') {
|
|
13
|
+
throw new TypeError(`first argument must be an HTML string, received ${html}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (html.length === 0) {
|
|
17
|
+
throw new RangeError('received empty string')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fileConfig = await Config.getMerged(process.env.NODE_ENV)
|
|
21
|
+
|
|
22
|
+
let config = merge(fileConfig, get(options, 'maizzle', {}))
|
|
23
|
+
|
|
24
|
+
const tailwindConfig = get(options, 'tailwind.config', {})
|
|
25
|
+
const cssString = get(options, 'tailwind.css', '')
|
|
26
|
+
|
|
27
|
+
let {frontmatter} = fm(html)
|
|
28
|
+
|
|
29
|
+
if (frontmatter) {
|
|
30
|
+
frontmatter = await posthtml(frontmatter, config)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
html = `---\n${frontmatter}\n---\n\n${fm(html).body}`
|
|
34
|
+
|
|
35
|
+
config = merge({applyTransformers: true}, config, fm(html).attributes)
|
|
36
|
+
|
|
37
|
+
if (typeof get(options, 'tailwind.compiled') === 'string') {
|
|
38
|
+
config.css = options.tailwind.compiled
|
|
39
|
+
} else {
|
|
40
|
+
config.css = await Tailwind.compile(cssString, html, tailwindConfig, config)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options && typeof options.beforeRender === 'function') {
|
|
44
|
+
html = await options.beforeRender(html, config)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
html = await posthtml(html, config)
|
|
48
|
+
|
|
49
|
+
while (Object.keys(fm(html).attributes).length > 0) {
|
|
50
|
+
html = fm(html).body
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options && typeof options.afterRender === 'function') {
|
|
54
|
+
html = await options.afterRender(html, config)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (config.applyTransformers) {
|
|
58
|
+
html = await Transformers.process(html, config)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options && typeof options.afterTransformers === 'function') {
|
|
62
|
+
html = await options.afterTransformers(html, config)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
html = await posthtmlMSO(html, config)
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
html,
|
|
69
|
+
config
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const {get} = require('lodash')
|
|
3
|
+
const postcss = require('postcss')
|
|
4
|
+
const postcssImport = require('postcss-import')
|
|
5
|
+
const postcssNested = require('tailwindcss/nesting')
|
|
6
|
+
const mergeLonghand = require('postcss-merge-longhand')
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
process: async (css = '', maizzleConfig = {}, spinner = null) => {
|
|
10
|
+
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))
|
|
11
|
+
|
|
12
|
+
return postcss([
|
|
13
|
+
postcssImport({path: path.dirname(userFilePath)}),
|
|
14
|
+
postcssNested(),
|
|
15
|
+
maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
|
|
16
|
+
...get(maizzleConfig, 'build.postcss.plugins', [])
|
|
17
|
+
])
|
|
18
|
+
.process(css, {from: undefined})
|
|
19
|
+
.then(result => result.css)
|
|
20
|
+
.catch(error => {
|
|
21
|
+
console.error(error)
|
|
22
|
+
if (spinner) {
|
|
23
|
+
spinner.stop()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new Error(`PostCSS processing failed`)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
const fm = require('front-matter')
|
|
2
|
-
const posthtml = require('posthtml')
|
|
3
|
-
const {get, merge} = require('lodash')
|
|
4
|
-
const fetch = require('posthtml-fetch')
|
|
5
|
-
const layouts = require('posthtml-extend')
|
|
6
|
-
const modules = require('posthtml-modules')
|
|
7
|
-
const expressions = require('posthtml-expressions')
|
|
8
|
-
|
|
9
|
-
module.exports = async (html, config) => {
|
|
10
|
-
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
1
|
+
const fm = require('front-matter')
|
|
2
|
+
const posthtml = require('posthtml')
|
|
3
|
+
const {get, merge} = require('lodash')
|
|
4
|
+
const fetch = require('posthtml-fetch')
|
|
5
|
+
const layouts = require('posthtml-extend')
|
|
6
|
+
const modules = require('posthtml-modules')
|
|
7
|
+
const expressions = require('posthtml-expressions')
|
|
8
|
+
|
|
9
|
+
module.exports = async (html, config) => {
|
|
10
|
+
const layoutsOptions = get(config, 'build.layouts', {})
|
|
11
|
+
|
|
12
|
+
const modulesOptions = get(config, 'build.components', {})
|
|
13
|
+
// Fake `from` option so we can reference modules relatively
|
|
14
|
+
const modulesRoot = modulesOptions.root || './'
|
|
15
|
+
const modulesFrom = modulesOptions.from || `${modulesRoot}/fake`
|
|
16
|
+
|
|
17
|
+
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
18
|
+
const posthtmlPlugins = get(config, 'build.posthtml.plugins', [])
|
|
19
|
+
|
|
20
|
+
const expressionsOptions = merge({strictMode: false}, get(config, 'build.posthtml.expressions', {}))
|
|
21
|
+
|
|
22
|
+
const locals = merge(
|
|
23
|
+
get(expressionsOptions, 'locals', {}),
|
|
24
|
+
get(config, 'locals', {}),
|
|
25
|
+
{page: config}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const fetchPlugin = fetch(
|
|
29
|
+
merge(
|
|
30
|
+
{
|
|
31
|
+
expressions: merge({...expressionsOptions, locals})
|
|
32
|
+
},
|
|
33
|
+
get(config, 'build.posthtml.fetch', {})
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return posthtml([
|
|
38
|
+
fetchPlugin,
|
|
39
|
+
expressions({...expressionsOptions, locals}),
|
|
40
|
+
layouts(
|
|
41
|
+
merge(
|
|
42
|
+
{
|
|
43
|
+
strict: false,
|
|
44
|
+
expressions: merge({...expressionsOptions, locals})
|
|
45
|
+
},
|
|
46
|
+
layoutsOptions
|
|
47
|
+
)
|
|
48
|
+
),
|
|
49
|
+
modules({
|
|
50
|
+
parser: posthtmlOptions,
|
|
51
|
+
attributeAsLocals: true,
|
|
52
|
+
from: modulesFrom,
|
|
53
|
+
root: modulesRoot,
|
|
54
|
+
tag: 'component',
|
|
55
|
+
attribute: 'src',
|
|
56
|
+
plugins: [
|
|
57
|
+
fetchPlugin
|
|
58
|
+
],
|
|
59
|
+
locals,
|
|
60
|
+
...modulesOptions
|
|
61
|
+
}),
|
|
62
|
+
...posthtmlPlugins
|
|
63
|
+
])
|
|
64
|
+
.process(html, {...posthtmlOptions})
|
|
65
|
+
.then(result => fm(result.html).body)
|
|
66
|
+
}
|
|
@@ -92,7 +92,7 @@ module.exports = {
|
|
|
92
92
|
if (userFileExists) {
|
|
93
93
|
css = await fs.readFile(path.resolve(userFilePath), 'utf8') + css
|
|
94
94
|
} else {
|
|
95
|
-
css =
|
|
95
|
+
css = `@import "tailwindcss/components"; @import "tailwindcss/utilities"; ${css}`
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
return postcss([
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
const serve = require('./commands/serve')
|
|
2
|
-
const toFile = require('./commands/build')
|
|
3
|
-
const transformers = require('./transformers')
|
|
4
|
-
const toString = require('./functions/render')
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
const serve = require('./commands/serve')
|
|
2
|
+
const toFile = require('./commands/build')
|
|
3
|
+
const transformers = require('./transformers')
|
|
4
|
+
const toString = require('./functions/render')
|
|
5
|
+
const PostCSS = require('./generators/postcss')
|
|
6
|
+
const toPlaintext = require('./functions/plaintext')
|
|
7
|
+
const TailwindCSS = require('./generators/tailwindcss')
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
serve,
|
|
11
|
+
build: toFile,
|
|
12
|
+
...transformers,
|
|
13
|
+
render: toString,
|
|
14
|
+
postcss: PostCSS,
|
|
15
|
+
plaintext: toPlaintext,
|
|
16
|
+
tailwindcss: TailwindCSS
|
|
17
|
+
}
|
|
@@ -3,17 +3,41 @@ const isUrl = require('is-url-superb')
|
|
|
3
3
|
const baseUrl = require('posthtml-base-url')
|
|
4
4
|
const {get, isObject, isEmpty} = require('lodash')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* VML backgrounds must be handled with regex because
|
|
8
|
+
* they're inside HTML comments.
|
|
9
|
+
*/
|
|
7
10
|
const rewriteVMLs = (html, url) => {
|
|
8
|
-
|
|
9
|
-
const
|
|
11
|
+
// Handle <v:image>
|
|
12
|
+
const vImageMatches = html.match(/<v:image[^>]+src="?([^"\s]+)"/g)
|
|
10
13
|
|
|
11
|
-
if (
|
|
12
|
-
|
|
14
|
+
if (vImageMatches) {
|
|
15
|
+
vImageMatches.forEach(match => {
|
|
16
|
+
const vImage = match.match(/<v:image[^>]+src="?([^"\s]+)"/)
|
|
17
|
+
const vImageSrc = vImage[1]
|
|
18
|
+
|
|
19
|
+
if (!isUrl(vImageSrc)) {
|
|
20
|
+
const vImageSrcUrl = url + vImageSrc
|
|
21
|
+
const vImageReplace = vImage[0].replace(vImageSrc, vImageSrcUrl)
|
|
22
|
+
html = html.replace(vImage[0], vImageReplace)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
// Handle <v:fill>
|
|
28
|
+
const vFillMatches = html.match(/<v:fill[^>]+src="?([^"\s]+)"/g)
|
|
29
|
+
|
|
30
|
+
if (vFillMatches) {
|
|
31
|
+
vFillMatches.forEach(match => {
|
|
32
|
+
const vFill = match.match(/<v:fill[^>]+src="?([^"\s]+)"/)
|
|
33
|
+
const vFillSrc = vFill[1]
|
|
34
|
+
|
|
35
|
+
if (!isUrl(vFillSrc)) {
|
|
36
|
+
const vFillSrcUrl = url + vFillSrc
|
|
37
|
+
const vFillReplace = vFill[0].replace(vFillSrc, vFillSrcUrl)
|
|
38
|
+
html = html.replace(vFill[0], vFillReplace)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
17
41
|
}
|
|
18
42
|
|
|
19
43
|
return html
|
|
@@ -23,7 +47,7 @@ module.exports = async (html, config = {}, direct = false) => {
|
|
|
23
47
|
const url = direct ? config : get(config, 'baseURL')
|
|
24
48
|
const posthtmlOptions = get(config, 'build.posthtml.options', {})
|
|
25
49
|
|
|
26
|
-
// `baseUrl` as a string
|
|
50
|
+
// Handle `baseUrl` as a string
|
|
27
51
|
if (typeof url === 'string' && url.length > 0) {
|
|
28
52
|
html = rewriteVMLs(html, url)
|
|
29
53
|
|
|
@@ -34,7 +58,7 @@ module.exports = async (html, config = {}, direct = false) => {
|
|
|
34
58
|
.then(result => result.html)
|
|
35
59
|
}
|
|
36
60
|
|
|
37
|
-
// `baseUrl
|
|
61
|
+
// Handle `baseUrl` as an object
|
|
38
62
|
if (isObject(url) && !isEmpty(url)) {
|
|
39
63
|
html = rewriteVMLs(html, url.url)
|
|
40
64
|
|