@maizzle/framework 5.0.0-beta.25 → 5.0.0-beta.27
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/package.json +11 -11
- package/src/generators/plaintext.js +3 -3
- package/src/generators/render.js +2 -2
- package/src/posthtml/defaultComponentsConfig.js +2 -2
- package/src/posthtml/defaultConfig.js +13 -3
- package/src/posthtml/index.js +2 -2
- package/src/transformers/addAttributes.js +1 -2
- package/src/transformers/attributeToStyle.js +1 -3
- package/src/transformers/baseUrl.js +6 -6
- package/src/transformers/comb.js +5 -4
- package/src/transformers/filters/index.js +1 -2
- package/src/transformers/index.js +27 -30
- package/src/transformers/inline.js +38 -11
- package/src/transformers/markdown.js +1 -3
- package/src/transformers/minify.js +4 -4
- package/src/transformers/posthtmlMso.js +1 -3
- package/src/transformers/prettify.js +3 -3
- package/src/transformers/preventWidows.js +2 -3
- package/src/transformers/removeAttributes.js +3 -4
- package/src/transformers/replaceStrings.js +3 -5
- package/src/transformers/safeClassNames.js +1 -2
- package/src/transformers/shorthandCss.js +1 -3
- package/src/transformers/sixHex.js +1 -3
- package/src/transformers/urlParameters.js +1 -3
- package/src/transformers/useAttributeSizes.js +1 -3
- package/src/utils/string.js +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maizzle/framework",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.27",
|
|
4
4
|
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"color-shorthand-hex-to-six-digit": "^5.0.16",
|
|
57
57
|
"defu": "^6.1.4",
|
|
58
58
|
"email-comb": "^7.0.21",
|
|
59
|
-
"express": "^4.
|
|
59
|
+
"express": "^4.21.0",
|
|
60
60
|
"fast-glob": "^3.3.2",
|
|
61
61
|
"gray-matter": "^4.0.3",
|
|
62
|
-
"html-crush": "^6.0.
|
|
62
|
+
"html-crush": "^6.0.19",
|
|
63
63
|
"is-url-superb": "^6.1.0",
|
|
64
64
|
"istextorbinary": "^9.5.0",
|
|
65
65
|
"juice": "^11.0.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"morphdom": "^2.7.4",
|
|
68
68
|
"ora": "^8.1.0",
|
|
69
69
|
"pathe": "^1.1.2",
|
|
70
|
-
"postcss": "^8.4.
|
|
70
|
+
"postcss": "^8.4.47",
|
|
71
71
|
"postcss-custom-properties": "^14.0.1",
|
|
72
72
|
"postcss-import": "^16.1.0",
|
|
73
73
|
"postcss-safe-parser": "^7.0.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"posthtml-fetch": "^4.0.0",
|
|
82
82
|
"posthtml-markdownit": "^3.1.0",
|
|
83
83
|
"posthtml-mso": "^3.1.0",
|
|
84
|
-
"posthtml-parser": "^0.12.
|
|
84
|
+
"posthtml-parser": "^0.12.1",
|
|
85
85
|
"posthtml-postcss": "^1.0.2",
|
|
86
86
|
"posthtml-postcss-merge-longhand": "^3.1.2",
|
|
87
87
|
"posthtml-render": "^3.0.0",
|
|
@@ -90,16 +90,16 @@
|
|
|
90
90
|
"pretty": "^2.0.0",
|
|
91
91
|
"string-remove-widows": "^4.0.22",
|
|
92
92
|
"string-strip-html": "^13.4.8",
|
|
93
|
-
"tailwindcss": "^3.4.
|
|
94
|
-
"ws": "^8.
|
|
93
|
+
"tailwindcss": "^3.4.13",
|
|
94
|
+
"ws": "^8.18.0"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@biomejs/biome": "1.
|
|
97
|
+
"@biomejs/biome": "1.9.2",
|
|
98
98
|
"@types/js-beautify": "^1.14.3",
|
|
99
|
-
"@types/markdown-it": "^14.1.
|
|
100
|
-
"@vitest/coverage-v8": "^2.
|
|
99
|
+
"@types/markdown-it": "^14.1.2",
|
|
100
|
+
"@vitest/coverage-v8": "^2.1.1",
|
|
101
101
|
"supertest": "^7.0.0",
|
|
102
|
-
"vitest": "^2.
|
|
102
|
+
"vitest": "^2.1.1"
|
|
103
103
|
},
|
|
104
104
|
"engines": {
|
|
105
105
|
"node": ">=18.20"
|
|
@@ -3,8 +3,8 @@ import posthtml from 'posthtml'
|
|
|
3
3
|
import get from 'lodash-es/get.js'
|
|
4
4
|
import { defu as merge } from 'defu'
|
|
5
5
|
import { stripHtml } from 'string-strip-html'
|
|
6
|
-
import defaultConfig from '../posthtml/defaultConfig.js'
|
|
7
6
|
import { writeFile, lstat, mkdir } from 'node:fs/promises'
|
|
7
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Removes HTML tags from a given HTML string based on
|
|
@@ -46,7 +46,7 @@ const removeTags = ({ tag = 'not-plaintext', html = '', config = {} }) => {
|
|
|
46
46
|
return tree.walk(process)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const posthtmlOptions = merge(
|
|
49
|
+
const posthtmlOptions = merge(config, getPosthtmlOptions())
|
|
50
50
|
|
|
51
51
|
return posthtml([posthtmlPlugin()]).process(html, { ...posthtmlOptions }).then(res => res.html)
|
|
52
52
|
}
|
|
@@ -95,7 +95,7 @@ export async function handlePlaintextTags(html = '', config = {}) {
|
|
|
95
95
|
return tree.walk(process)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const posthtmlOptions = merge(
|
|
98
|
+
const posthtmlOptions = merge(config, getPosthtmlOptions())
|
|
99
99
|
|
|
100
100
|
return posthtml([posthtmlPlugin()]).process(html, { ...posthtmlOptions }).then(res => res.html)
|
|
101
101
|
}
|
package/src/generators/render.js
CHANGED
|
@@ -4,7 +4,7 @@ import { cwd } from 'node:process'
|
|
|
4
4
|
import { defu as merge } from 'defu'
|
|
5
5
|
import expressions from 'posthtml-expressions'
|
|
6
6
|
import { parseFrontMatter } from '../utils/node.js'
|
|
7
|
-
import
|
|
7
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
8
|
import { process as compilePostHTML } from '../posthtml/index.js'
|
|
9
9
|
import { run as useTransformers } from '../transformers/index.js'
|
|
10
10
|
|
|
@@ -41,7 +41,7 @@ export async function render(html = '', config = {}) {
|
|
|
41
41
|
})
|
|
42
42
|
]
|
|
43
43
|
)
|
|
44
|
-
.process(matter,
|
|
44
|
+
.process(matter, getPosthtmlOptions())
|
|
45
45
|
.then(({ html }) => parseFrontMatter(`---${html}\n---`))
|
|
46
46
|
|
|
47
47
|
const templateConfig = merge(matterData, config)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
root: './',
|
|
3
|
-
folders: ['src/components', 'src/layouts', 'src/templates'],
|
|
4
|
-
fileExtension: 'html',
|
|
5
3
|
tag: 'component',
|
|
4
|
+
fileExtension: 'html',
|
|
5
|
+
folders: ['src/components', 'src/layouts', 'src/templates'],
|
|
6
6
|
expressions: {
|
|
7
7
|
loopTags: ['each', 'for'],
|
|
8
8
|
missingLocal: '{local}',
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { defu as merge } from 'defu'
|
|
2
|
+
|
|
3
|
+
export function getPosthtmlOptions(userConfigOptions = {}) {
|
|
4
|
+
return merge(
|
|
5
|
+
userConfigOptions,
|
|
6
|
+
{
|
|
7
|
+
recognizeNoValueAttribute: true,
|
|
8
|
+
recognizeSelfClosing: true,
|
|
9
|
+
directives: [
|
|
10
|
+
{ name: '?php', start: '<', end: '>' },
|
|
11
|
+
],
|
|
12
|
+
}
|
|
13
|
+
)
|
|
4
14
|
}
|
package/src/posthtml/index.js
CHANGED
|
@@ -7,9 +7,9 @@ import posthtmlFetch from 'posthtml-fetch'
|
|
|
7
7
|
import envTags from './plugins/envTags.js'
|
|
8
8
|
import components from 'posthtml-component'
|
|
9
9
|
import posthtmlPostcss from 'posthtml-postcss'
|
|
10
|
-
import defaultPosthtmlConfig from './defaultConfig.js'
|
|
11
10
|
import expandLinkTag from './plugins/expandLinkTag.js'
|
|
12
11
|
import envAttributes from './plugins/envAttributes.js'
|
|
12
|
+
import { getPosthtmlOptions } from './defaultConfig.js'
|
|
13
13
|
|
|
14
14
|
// PostCSS
|
|
15
15
|
import tailwindcss from 'tailwindcss'
|
|
@@ -36,7 +36,7 @@ export async function process(html = '', config = {}) {
|
|
|
36
36
|
)
|
|
37
37
|
)
|
|
38
38
|
|
|
39
|
-
const posthtmlOptions =
|
|
39
|
+
const posthtmlOptions = getPosthtmlOptions(get(config, 'posthtml.options', {}))
|
|
40
40
|
|
|
41
41
|
const componentsUserOptions = get(config, 'components', {})
|
|
42
42
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
4
3
|
import addAttributesPlugin from 'posthtml-extra-attributes'
|
|
5
4
|
|
|
6
5
|
export default function posthtmlPlugin(attributes = {}) {
|
|
@@ -25,6 +24,6 @@ export async function addAttributes(html = '', attributes = {}, posthtmlOptions
|
|
|
25
24
|
return posthtml([
|
|
26
25
|
posthtmlPlugin(attributes)
|
|
27
26
|
])
|
|
28
|
-
.process(html,
|
|
27
|
+
.process(html, posthtmlOptions)
|
|
29
28
|
.then(result => result.html)
|
|
30
29
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import get from 'lodash-es/get.js'
|
|
3
|
-
import { defu as merge } from 'defu'
|
|
4
3
|
import keys from 'lodash-es/keys.js'
|
|
5
4
|
import forEach from 'lodash-es/forEach.js'
|
|
6
5
|
import parseAttrs from 'posthtml-attrs-parser'
|
|
7
6
|
import intersection from 'lodash-es/intersection.js'
|
|
8
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
9
7
|
|
|
10
8
|
const posthtmlPlugin = (attributes = []) => tree => {
|
|
11
9
|
if (!Array.isArray(attributes)) {
|
|
@@ -87,6 +85,6 @@ export async function attributeToStyle(html = '', attributes = [], posthtmlOptio
|
|
|
87
85
|
return posthtml([
|
|
88
86
|
posthtmlPlugin(attributes)
|
|
89
87
|
])
|
|
90
|
-
.process(html,
|
|
88
|
+
.process(html, posthtmlOptions)
|
|
91
89
|
.then(result => result.html)
|
|
92
90
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import isUrl from 'is-url-superb'
|
|
3
3
|
import get from 'lodash-es/get.js'
|
|
4
|
-
import { defu as merge } from 'defu'
|
|
5
4
|
import baseUrl from 'posthtml-base-url'
|
|
6
5
|
import { render } from 'posthtml-render'
|
|
7
6
|
import isEmpty from 'lodash-es/isEmpty.js'
|
|
8
7
|
import isObject from 'lodash-es/isObject.js'
|
|
9
8
|
import { parser as parse } from 'posthtml-parser'
|
|
10
|
-
import
|
|
9
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
10
|
+
|
|
11
|
+
const posthtmlOptions = getPosthtmlOptions()
|
|
11
12
|
|
|
12
13
|
const posthtmlPlugin = url => tree => {
|
|
13
14
|
// Handle `baseURL` as a string
|
|
@@ -19,7 +20,7 @@ const posthtmlPlugin = url => tree => {
|
|
|
19
20
|
allTags: true,
|
|
20
21
|
styleTag: true,
|
|
21
22
|
inlineCss: true
|
|
22
|
-
})(parse(html,
|
|
23
|
+
})(parse(html, posthtmlOptions))
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// Handle `baseURL` as an object
|
|
@@ -31,7 +32,6 @@ const posthtmlPlugin = url => tree => {
|
|
|
31
32
|
allTags,
|
|
32
33
|
tags,
|
|
33
34
|
url: baseURL,
|
|
34
|
-
...posthtmlOptions
|
|
35
35
|
} = url
|
|
36
36
|
|
|
37
37
|
return baseUrl({
|
|
@@ -40,7 +40,7 @@ const posthtmlPlugin = url => tree => {
|
|
|
40
40
|
allTags,
|
|
41
41
|
tags,
|
|
42
42
|
url: baseURL,
|
|
43
|
-
})(parse(html,
|
|
43
|
+
})(parse(html, posthtmlOptions))
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return tree
|
|
@@ -52,7 +52,7 @@ export async function addBaseUrl(html = '', options = {}, posthtmlOptions = {})
|
|
|
52
52
|
return posthtml([
|
|
53
53
|
posthtmlPlugin(options)
|
|
54
54
|
])
|
|
55
|
-
.process(html,
|
|
55
|
+
.process(html, getPosthtmlOptions())
|
|
56
56
|
.then(result => result.html)
|
|
57
57
|
}
|
|
58
58
|
|
package/src/transformers/comb.js
CHANGED
|
@@ -4,7 +4,7 @@ import { defu as merge } from 'defu'
|
|
|
4
4
|
import { render } from 'posthtml-render'
|
|
5
5
|
import { comb as emailComb } from 'email-comb'
|
|
6
6
|
import { parser as parse } from 'posthtml-parser'
|
|
7
|
-
import
|
|
7
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
8
|
|
|
9
9
|
const posthtmlPlugin = options => tree => {
|
|
10
10
|
const defaultSafelist = [
|
|
@@ -35,6 +35,7 @@ const posthtmlPlugin = options => tree => {
|
|
|
35
35
|
|
|
36
36
|
options = merge(options, defaultOptions)
|
|
37
37
|
|
|
38
|
+
const posthtmlConfig = getPosthtmlOptions()
|
|
38
39
|
const { result: html } = emailComb(render(tree), options)
|
|
39
40
|
|
|
40
41
|
return parse(html, posthtmlConfig)
|
|
@@ -42,10 +43,10 @@ const posthtmlPlugin = options => tree => {
|
|
|
42
43
|
|
|
43
44
|
export default posthtmlPlugin
|
|
44
45
|
|
|
45
|
-
export async function comb(html = '',
|
|
46
|
+
export async function comb(html = '', pluginOptions = {}, posthtmlOptions = {}) {
|
|
46
47
|
return posthtml([
|
|
47
|
-
posthtmlPlugin(
|
|
48
|
+
posthtmlPlugin(pluginOptions)
|
|
48
49
|
])
|
|
49
|
-
.process(html,
|
|
50
|
+
.process(html, posthtmlOptions)
|
|
50
51
|
.then(result => result.html)
|
|
51
52
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
3
|
import posthtmlContent from 'posthtml-content'
|
|
4
|
-
import posthtmlConfig from '../../posthtml/defaultConfig.js'
|
|
5
4
|
import { filters as defaultFilters } from './defaultFilters.js'
|
|
6
5
|
|
|
7
6
|
export default function posthtmlPlugin(filters = {}) {
|
|
@@ -14,6 +13,6 @@ export async function filters(html = '', filters = {}, posthtmlOptions = {}) {
|
|
|
14
13
|
return posthtml([
|
|
15
14
|
posthtmlPlugin(filters)
|
|
16
15
|
])
|
|
17
|
-
.process(html,
|
|
16
|
+
.process(html, posthtmlOptions)
|
|
18
17
|
.then(result => result.html)
|
|
19
18
|
}
|
|
@@ -22,7 +22,7 @@ import replaceStrings from './replaceStrings.js'
|
|
|
22
22
|
import attributeToStyle from './attributeToStyle.js'
|
|
23
23
|
import removeAttributes from './removeAttributes.js'
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Use Maizzle Transformers on an HTML string.
|
|
@@ -37,10 +37,7 @@ import defaultPosthtmlConfig from '../posthtml/defaultConfig.js'
|
|
|
37
37
|
export async function run(html = '', config = {}) {
|
|
38
38
|
const posthtmlPlugins = []
|
|
39
39
|
|
|
40
|
-
const posthtmlConfig =
|
|
41
|
-
get(config, 'posthtml.options', {}),
|
|
42
|
-
defaultPosthtmlConfig
|
|
43
|
-
)
|
|
40
|
+
const posthtmlConfig = getPosthtmlOptions(get(config, 'posthtml.options', {}))
|
|
44
41
|
|
|
45
42
|
/**
|
|
46
43
|
* 1. Core transformers
|
|
@@ -124,16 +121,7 @@ export async function run(html = '', config = {}) {
|
|
|
124
121
|
}
|
|
125
122
|
|
|
126
123
|
/**
|
|
127
|
-
* 8.
|
|
128
|
-
*
|
|
129
|
-
* Remove unused CSS, uglify classes etc.
|
|
130
|
-
*/
|
|
131
|
-
if (get(config, 'css.purge')) {
|
|
132
|
-
posthtmlPlugins.push(comb(config.css.purge))
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 9. Remove attributes
|
|
124
|
+
* 8. Remove attributes
|
|
137
125
|
*
|
|
138
126
|
* Remove attributes from HTML tags
|
|
139
127
|
* If `undefined`, removes empty `style` and `class` attributes
|
|
@@ -148,7 +136,7 @@ export async function run(html = '', config = {}) {
|
|
|
148
136
|
}
|
|
149
137
|
|
|
150
138
|
/**
|
|
151
|
-
*
|
|
139
|
+
* 9. Shorthand CSS
|
|
152
140
|
*
|
|
153
141
|
* Convert longhand CSS properties to shorthand in `style` attributes.
|
|
154
142
|
*/
|
|
@@ -159,7 +147,7 @@ export async function run(html = '', config = {}) {
|
|
|
159
147
|
}
|
|
160
148
|
|
|
161
149
|
/**
|
|
162
|
-
*
|
|
150
|
+
* 10. Add attributes
|
|
163
151
|
*
|
|
164
152
|
* Add attributes to HTML tags.
|
|
165
153
|
*/
|
|
@@ -170,7 +158,7 @@ export async function run(html = '', config = {}) {
|
|
|
170
158
|
}
|
|
171
159
|
|
|
172
160
|
/**
|
|
173
|
-
*
|
|
161
|
+
* 11. Base URL
|
|
174
162
|
*
|
|
175
163
|
* Add a base URL to relative paths.
|
|
176
164
|
*/
|
|
@@ -181,7 +169,7 @@ export async function run(html = '', config = {}) {
|
|
|
181
169
|
}
|
|
182
170
|
|
|
183
171
|
/**
|
|
184
|
-
*
|
|
172
|
+
* 12. URL parameters
|
|
185
173
|
*
|
|
186
174
|
* Add parameters to URLs.
|
|
187
175
|
*/
|
|
@@ -192,7 +180,7 @@ export async function run(html = '', config = {}) {
|
|
|
192
180
|
}
|
|
193
181
|
|
|
194
182
|
/**
|
|
195
|
-
*
|
|
183
|
+
* 13. Six-digit HEX
|
|
196
184
|
*
|
|
197
185
|
* Enabled by default, converts three-digit HEX colors to six-digit.
|
|
198
186
|
*/
|
|
@@ -203,7 +191,7 @@ export async function run(html = '', config = {}) {
|
|
|
203
191
|
}
|
|
204
192
|
|
|
205
193
|
/**
|
|
206
|
-
*
|
|
194
|
+
* 14. PostHTML MSO
|
|
207
195
|
*
|
|
208
196
|
* Enabled by default, simplifies writing MSO conditionals for Outlook.
|
|
209
197
|
*/
|
|
@@ -214,7 +202,23 @@ export async function run(html = '', config = {}) {
|
|
|
214
202
|
}
|
|
215
203
|
|
|
216
204
|
/**
|
|
217
|
-
*
|
|
205
|
+
* 15. Purge CSS
|
|
206
|
+
*
|
|
207
|
+
* Remove unused CSS, uglify classes etc.
|
|
208
|
+
*/
|
|
209
|
+
if (get(config, 'css.purge')) {
|
|
210
|
+
posthtmlPlugins.push(comb(config.css.purge))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 16. <template> tags
|
|
215
|
+
*
|
|
216
|
+
* Replace <template> tags with their content.
|
|
217
|
+
*/
|
|
218
|
+
posthtmlPlugins.push(templateTag())
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 17. Prettify
|
|
218
222
|
*
|
|
219
223
|
* Pretty-print HTML using js-beautify.
|
|
220
224
|
*/
|
|
@@ -225,7 +229,7 @@ export async function run(html = '', config = {}) {
|
|
|
225
229
|
}
|
|
226
230
|
|
|
227
231
|
/**
|
|
228
|
-
*
|
|
232
|
+
* 18. Minify
|
|
229
233
|
*
|
|
230
234
|
* Minify HTML using html-crush.
|
|
231
235
|
*/
|
|
@@ -235,13 +239,6 @@ export async function run(html = '', config = {}) {
|
|
|
235
239
|
)
|
|
236
240
|
}
|
|
237
241
|
|
|
238
|
-
/**
|
|
239
|
-
* 18. <template> tags
|
|
240
|
-
*
|
|
241
|
-
* Replace <template> tags with their content.
|
|
242
|
-
*/
|
|
243
|
-
posthtmlPlugins.push(templateTag())
|
|
244
|
-
|
|
245
242
|
/**
|
|
246
243
|
* 19. Replace strings
|
|
247
244
|
*
|
|
@@ -12,10 +12,10 @@ import isObject from 'lodash-es/isObject.js'
|
|
|
12
12
|
import { parser as parse } from 'posthtml-parser'
|
|
13
13
|
import { parseCSSRule } from '../utils/string.js'
|
|
14
14
|
import { useAttributeSizes } from './useAttributeSizes.js'
|
|
15
|
-
import
|
|
15
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
16
16
|
|
|
17
17
|
const posthtmlPlugin = (options = {}) => tree => {
|
|
18
|
-
return inline(render(tree), options).then(html => parse(html,
|
|
18
|
+
return inline(render(tree), options).then(html => parse(html, getPosthtmlOptions()))
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default posthtmlPlugin
|
|
@@ -55,9 +55,12 @@ export async function inline(html = '', options = {}) {
|
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
// Add a `data-embed` attribute to style tags that have the embed attribute
|
|
58
|
-
$('style[embed]').each((i, el) => {
|
|
58
|
+
$('style[embed]:not([data-embed])').each((i, el) => {
|
|
59
59
|
$(el).attr('data-embed', '')
|
|
60
60
|
})
|
|
61
|
+
$('style[data-embed]:not([embed])').each((i, el) => {
|
|
62
|
+
$(el).attr('embed', '')
|
|
63
|
+
})
|
|
61
64
|
|
|
62
65
|
/**
|
|
63
66
|
* Inline the CSS
|
|
@@ -103,7 +106,31 @@ export async function inline(html = '', options = {}) {
|
|
|
103
106
|
}
|
|
104
107
|
)
|
|
105
108
|
|
|
106
|
-
const preservedClasses = new Set(
|
|
109
|
+
const preservedClasses = new Set([
|
|
110
|
+
'.body', // Gmail
|
|
111
|
+
'.gmail', // Gmail
|
|
112
|
+
'.apple', // Apple Mail
|
|
113
|
+
'.ios', // Mail on iOS
|
|
114
|
+
'.ox-', // Open-Xchange
|
|
115
|
+
'.outlook', // Outlook.com
|
|
116
|
+
'[data-ogs', // Outlook.com
|
|
117
|
+
'.bloop_container', // Airmail
|
|
118
|
+
'.Singleton', // Apple Mail 10
|
|
119
|
+
'.unused', // Notes 8
|
|
120
|
+
'.moz-text-html', // Thunderbird
|
|
121
|
+
'.mail-detail-content', // Comcast, Libero webmail
|
|
122
|
+
'edo', // Edison (all)
|
|
123
|
+
'#msgBody', // Freenet uses #msgBody
|
|
124
|
+
'.lang' // Fenced code blocks
|
|
125
|
+
])
|
|
126
|
+
|
|
127
|
+
// Precompile a single regex to match any substring from the preservedClasses set
|
|
128
|
+
const combinedPattern = Array.from(preservedClasses)
|
|
129
|
+
.map(pattern => pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')) // Escape special regex chars
|
|
130
|
+
.join('|') // Combine all patterns into a single regex pattern with 'OR' (|)
|
|
131
|
+
|
|
132
|
+
const combinedRegex = new RegExp(combinedPattern)
|
|
133
|
+
|
|
107
134
|
const selectors = new Set()
|
|
108
135
|
|
|
109
136
|
// Preserve selectors in at rules
|
|
@@ -123,7 +150,7 @@ export async function inline(html = '', options = {}) {
|
|
|
123
150
|
rule.walkDecls(decl => {
|
|
124
151
|
// Resolve calc() values to static values
|
|
125
152
|
if (options.resolveCalc) {
|
|
126
|
-
decl.value = decl.value.includes('calc(') ? calc(decl.value, {precision: 2}) : decl.value
|
|
153
|
+
decl.value = decl.value.includes('calc(') ? calc(decl.value, { precision: 2 }) : decl.value
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
declarations.add(decl)
|
|
@@ -137,10 +164,10 @@ export async function inline(html = '', options = {}) {
|
|
|
137
164
|
*/
|
|
138
165
|
if (options.resolveCSSVariables) {
|
|
139
166
|
Array.from(declarations)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Consider only declarations with a value that includes any of the other declarations' property
|
|
169
|
+
* So a decl like color(var(--text-color)) will be removed if there's a decl with a property of --text-color
|
|
170
|
+
* */
|
|
144
171
|
.filter(decl =>
|
|
145
172
|
Array.from(declarations).some(otherDecl => decl.value.includes(otherDecl.prop))
|
|
146
173
|
|| decl.prop.startsWith('--')
|
|
@@ -163,7 +190,7 @@ export async function inline(html = '', options = {}) {
|
|
|
163
190
|
|
|
164
191
|
if (options.removeInlinedSelectors) {
|
|
165
192
|
// Remove the rule in the <style> tag as long as it's not a preserved class
|
|
166
|
-
if (!preservedClasses.has(selector)) {
|
|
193
|
+
if (!preservedClasses.has(selector) && !combinedRegex.test(selector)) {
|
|
167
194
|
rule.remove()
|
|
168
195
|
}
|
|
169
196
|
|
|
@@ -189,7 +216,7 @@ export async function inline(html = '', options = {}) {
|
|
|
189
216
|
let { property, value } = parseCSSRule(i)
|
|
190
217
|
|
|
191
218
|
if (value && options.resolveCalc) {
|
|
192
|
-
value = value.includes('calc') ? calc(value, {precision: 2}) : value
|
|
219
|
+
value = value.includes('calc') ? calc(value, { precision: 2 }) : value
|
|
193
220
|
}
|
|
194
221
|
|
|
195
222
|
if (value && options.preferUnitlessValues) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import { defu as merge } from 'defu'
|
|
3
2
|
import md from 'posthtml-markdownit'
|
|
4
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
5
3
|
|
|
6
4
|
export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
|
|
7
5
|
/**
|
|
@@ -23,6 +21,6 @@ export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
|
|
|
23
21
|
return posthtml([
|
|
24
22
|
md(options)
|
|
25
23
|
])
|
|
26
|
-
.process(input,
|
|
24
|
+
.process(input, posthtmlOptions)
|
|
27
25
|
.then(result => result.html)
|
|
28
26
|
}
|
|
@@ -3,17 +3,17 @@ import { crush } from 'html-crush'
|
|
|
3
3
|
import { defu as merge } from 'defu'
|
|
4
4
|
import { render } from 'posthtml-render'
|
|
5
5
|
import { parser as parse } from 'posthtml-parser'
|
|
6
|
-
import
|
|
7
|
-
import defaultPostHTMLConfig from '../posthtml/defaultConfig.js'
|
|
6
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
7
|
|
|
9
8
|
const posthtmlPlugin = (options = {}) => tree => {
|
|
10
9
|
options = merge(options, {
|
|
11
10
|
removeLineBreaks: true,
|
|
12
11
|
})
|
|
13
12
|
|
|
13
|
+
const posthtmlConfig = getPosthtmlOptions()
|
|
14
14
|
const { result: html } = crush(render(tree), options)
|
|
15
15
|
|
|
16
|
-
return parse(html,
|
|
16
|
+
return parse(html, posthtmlConfig)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export default posthtmlPlugin
|
|
@@ -22,6 +22,6 @@ export async function minify(html = '', options = {}, posthtmlOptions = {}) {
|
|
|
22
22
|
return posthtml([
|
|
23
23
|
posthtmlPlugin(options)
|
|
24
24
|
])
|
|
25
|
-
.process(html,
|
|
25
|
+
.process(html, posthtmlOptions)
|
|
26
26
|
.then(result => result.html)
|
|
27
27
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import { defu as merge } from 'defu'
|
|
3
2
|
import posthtmlMso from 'posthtml-mso'
|
|
4
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
5
3
|
|
|
6
4
|
export default function posthtmlPlugin(options = {}) {
|
|
7
5
|
return posthtmlMso(options)
|
|
@@ -11,6 +9,6 @@ export async function useMso(html = '', options = {}, posthtmlOptions = {}) {
|
|
|
11
9
|
return posthtml([
|
|
12
10
|
posthtmlPlugin(options)
|
|
13
11
|
])
|
|
14
|
-
.process(html,
|
|
12
|
+
.process(html, posthtmlOptions)
|
|
15
13
|
.then(result => result.html)
|
|
16
14
|
}
|
|
@@ -3,7 +3,7 @@ import posthtml from 'posthtml'
|
|
|
3
3
|
import { defu as merge } from 'defu'
|
|
4
4
|
import { render } from 'posthtml-render'
|
|
5
5
|
import { parser as parse } from 'posthtml-parser'
|
|
6
|
-
import
|
|
6
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
7
7
|
|
|
8
8
|
const posthtmlPlugin = (options = {}) => tree => {
|
|
9
9
|
const defaultConfig = {
|
|
@@ -15,7 +15,7 @@ const posthtmlPlugin = (options = {}) => tree => {
|
|
|
15
15
|
|
|
16
16
|
const config = merge(options, defaultConfig)
|
|
17
17
|
|
|
18
|
-
return parse(pretty(render(tree), config),
|
|
18
|
+
return parse(pretty(render(tree), config), getPosthtmlOptions())
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default posthtmlPlugin
|
|
@@ -24,6 +24,6 @@ export async function prettify(html = '', options = {}, posthtmlOptions = {}) {
|
|
|
24
24
|
return posthtml([
|
|
25
25
|
posthtmlPlugin(options)
|
|
26
26
|
])
|
|
27
|
-
.process(html,
|
|
27
|
+
.process(html, posthtmlOptions)
|
|
28
28
|
.then(result => result.html)
|
|
29
29
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
3
|
import { removeWidows } from 'string-remove-widows'
|
|
4
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
5
4
|
|
|
6
5
|
const posthtmlPlugin = (options = {}) => tree => {
|
|
7
6
|
options = merge(options, {
|
|
8
7
|
minWordCount: 3,
|
|
9
|
-
attrName: '
|
|
8
|
+
attrName: 'no-widows'
|
|
10
9
|
})
|
|
11
10
|
|
|
12
11
|
// Ignore defaults
|
|
@@ -78,7 +77,7 @@ export async function preventWidows(html = '', options = {}, posthtmlOptions = {
|
|
|
78
77
|
return posthtml([
|
|
79
78
|
posthtmlPlugin(options)
|
|
80
79
|
])
|
|
81
|
-
.process(html,
|
|
80
|
+
.process(html, posthtmlOptions)
|
|
82
81
|
.then(result => result.html)
|
|
83
82
|
}
|
|
84
83
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import get from 'lodash-es/get.js'
|
|
3
|
-
import {
|
|
4
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
3
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Remove empty attributes with PostHTML
|
|
@@ -49,8 +48,8 @@ export default posthtmlPlugin
|
|
|
49
48
|
|
|
50
49
|
export async function removeAttributes(html = '', attributes = [], posthtmlOptions = {}) {
|
|
51
50
|
return posthtml([
|
|
52
|
-
posthtmlPlugin(attributes,
|
|
51
|
+
posthtmlPlugin(attributes, getPosthtmlOptions(posthtmlOptions))
|
|
53
52
|
])
|
|
54
|
-
.process(html,
|
|
53
|
+
.process(html, getPosthtmlOptions())
|
|
55
54
|
.then(result => result.html)
|
|
56
55
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import { defu as merge } from 'defu'
|
|
3
2
|
import { render } from 'posthtml-render'
|
|
4
3
|
import isEmpty from 'lodash-es/isEmpty.js'
|
|
5
4
|
import { parser as parse } from 'posthtml-parser'
|
|
6
|
-
import
|
|
7
|
-
import defaultPostHTMLConfig from '../posthtml/defaultConfig.js'
|
|
5
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
6
|
|
|
9
7
|
const posthtmlPlugin = (replacements = {}) => tree => {
|
|
10
8
|
if (!isEmpty(replacements)) {
|
|
@@ -21,7 +19,7 @@ const posthtmlPlugin = (replacements = {}) => tree => {
|
|
|
21
19
|
|
|
22
20
|
return matched
|
|
23
21
|
}),
|
|
24
|
-
|
|
22
|
+
getPosthtmlOptions()
|
|
25
23
|
)
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -34,6 +32,6 @@ export async function replaceStrings(html = '', replacements = {}, posthtmlOptio
|
|
|
34
32
|
return posthtml([
|
|
35
33
|
posthtmlPlugin(replacements)
|
|
36
34
|
])
|
|
37
|
-
.process(html,
|
|
35
|
+
.process(html, posthtmlOptions)
|
|
38
36
|
.then(result => result.html)
|
|
39
37
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
4
3
|
import posthtmlSafeClassNames from 'posthtml-safe-class-names'
|
|
5
4
|
|
|
6
5
|
export default function posthtmlPlugin(options = {}) {
|
|
@@ -24,6 +23,6 @@ export async function safeClassNames(html = '', options = {}, posthtmlOptions =
|
|
|
24
23
|
return posthtml([
|
|
25
24
|
posthtmlPlugin(options)
|
|
26
25
|
])
|
|
27
|
-
.process(html,
|
|
26
|
+
.process(html, posthtmlOptions)
|
|
28
27
|
.then(result => result.html)
|
|
29
28
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import { defu as merge } from 'defu'
|
|
3
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
4
2
|
import posthtmlMergeLonghand from 'posthtml-postcss-merge-longhand'
|
|
5
3
|
|
|
6
4
|
export default function posthtmlPlugin(options = {}) {
|
|
@@ -17,6 +15,6 @@ export async function shorthandCSS(html = '', options = {}, posthtmlOptions = {}
|
|
|
17
15
|
return posthtml([
|
|
18
16
|
posthtmlPlugin(options)
|
|
19
17
|
])
|
|
20
|
-
.process(html,
|
|
18
|
+
.process(html, posthtmlOptions)
|
|
21
19
|
.then(result => result.html)
|
|
22
20
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import { defu as merge } from 'defu'
|
|
3
2
|
import { conv } from 'color-shorthand-hex-to-six-digit'
|
|
4
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
5
3
|
|
|
6
4
|
const posthtmlPlugin = () => tree => {
|
|
7
5
|
const targets = new Set(['bgcolor', 'color'])
|
|
@@ -27,6 +25,6 @@ export async function sixHEX(html = '', posthtmlOptions = {}) {
|
|
|
27
25
|
return posthtml([
|
|
28
26
|
posthtmlPlugin()
|
|
29
27
|
])
|
|
30
|
-
.process(html,
|
|
28
|
+
.process(html, posthtmlOptions)
|
|
31
29
|
.then(result => result.html)
|
|
32
30
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import get from 'lodash-es/get.js'
|
|
3
|
-
import { defu as merge } from 'defu'
|
|
4
3
|
import urlParameters from 'posthtml-url-parameters'
|
|
5
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
6
4
|
|
|
7
5
|
export default function posthtmlPlugin(options = {}) {
|
|
8
6
|
const { _options, ...parameters } = options
|
|
@@ -17,6 +15,6 @@ export async function addURLParams(html = '', options = {}, posthtmlOptions = {}
|
|
|
17
15
|
return posthtml([
|
|
18
16
|
posthtmlPlugin(options)
|
|
19
17
|
])
|
|
20
|
-
.process(html,
|
|
18
|
+
.process(html, posthtmlOptions)
|
|
21
19
|
.then(result => result.html)
|
|
22
20
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import postcss from 'postcss'
|
|
2
2
|
import posthtml from 'posthtml'
|
|
3
3
|
import get from 'lodash-es/get.js'
|
|
4
|
-
import { defu as merge } from 'defu'
|
|
5
|
-
import posthtmlConfig from '../posthtml/defaultConfig.js'
|
|
6
4
|
|
|
7
5
|
const posthtmlPlugin = (mappings = {}) => tree => {
|
|
8
6
|
if (!Object.keys(mappings).length) {
|
|
@@ -60,6 +58,6 @@ export async function useAttributeSizes(html = '', mappings = {}, posthtmlOption
|
|
|
60
58
|
return posthtml([
|
|
61
59
|
posthtmlPlugin(mappings)
|
|
62
60
|
])
|
|
63
|
-
.process(html,
|
|
61
|
+
.process(html, posthtmlOptions)
|
|
64
62
|
.then(result => result.html)
|
|
65
63
|
}
|
package/src/utils/string.js
CHANGED
|
@@ -194,3 +194,13 @@ export function parseCSSRule(rule) {
|
|
|
194
194
|
|
|
195
195
|
return { property, value }
|
|
196
196
|
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Normalize a string by removing extra whitespace.
|
|
200
|
+
*
|
|
201
|
+
* @param {String} str The string to clean
|
|
202
|
+
* @returns {String} The cleaned string
|
|
203
|
+
*/
|
|
204
|
+
export function cleanString(str) {
|
|
205
|
+
return str.replace(/\s+/g, ' ').trim()
|
|
206
|
+
}
|