@maizzle/framework 6.0.0-11 → 6.0.0-13
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/CHANGELOG.md +21 -0
- package/package.json +1 -1
- package/src/transformers/addAttributes.js +2 -1
- package/src/transformers/attributeToStyle.js +2 -1
- package/src/transformers/baseUrl.js +6 -6
- package/src/transformers/filters/index.js +2 -1
- package/src/transformers/index.js +44 -31
- package/src/transformers/inline.js +8 -6
- package/src/transformers/markdown.js +16 -6
- package/src/transformers/minify.js +5 -4
- package/src/transformers/posthtmlMso.js +2 -1
- package/src/transformers/prettify.js +5 -3
- package/src/transformers/preventWidows.js +3 -2
- package/src/transformers/purge.js +6 -5
- package/src/transformers/removeAttributes.js +4 -2
- package/src/transformers/replaceCssProperties.js +55 -0
- package/src/transformers/replaceStrings.js +1 -1
- package/src/transformers/safeClassNames.js +2 -1
- package/src/transformers/shorthandCss.js +2 -1
- package/src/transformers/sixHex.js +2 -1
- package/src/transformers/urlParameters.js +2 -1
- package/src/transformers/useAttributeSizes.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [6.0.0-13] - 2025-07-17
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- feat: replace css properties transformer 8e9b6af
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- fix: default posthtml options for the prettify transformer a5916ec
|
|
16
|
+
- fix: ensure user posthtml options are used by all transformers 2fa7e1c
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- refactor: cache posthtml options in inliner 173aa3f
|
|
21
|
+
|
|
22
|
+
## [6.0.0-12] - 2025-07-17
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- fix: @container class safelisting b4d02f1
|
|
27
|
+
|
|
7
28
|
## [6.0.0-11] - 2025-07-16
|
|
8
29
|
|
|
9
30
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
3
|
import addAttributesPlugin from 'posthtml-extra-attributes'
|
|
4
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
4
5
|
|
|
5
6
|
export default function posthtmlPlugin(attributes = {}) {
|
|
6
7
|
const defaultAttributes = {
|
|
@@ -24,6 +25,6 @@ export async function addAttributes(html = '', attributes = {}, posthtmlOptions
|
|
|
24
25
|
return posthtml([
|
|
25
26
|
posthtmlPlugin(attributes)
|
|
26
27
|
])
|
|
27
|
-
.process(html, posthtmlOptions)
|
|
28
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
28
29
|
.then(result => result.html)
|
|
29
30
|
}
|
|
@@ -4,6 +4,7 @@ import keys from 'lodash-es/keys.js'
|
|
|
4
4
|
import forEach from 'lodash-es/forEach.js'
|
|
5
5
|
import parseAttrs from 'posthtml-attrs-parser'
|
|
6
6
|
import intersection from 'lodash-es/intersection.js'
|
|
7
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
7
8
|
|
|
8
9
|
const posthtmlPlugin = (attributes = []) => tree => {
|
|
9
10
|
if (!Array.isArray(attributes)) {
|
|
@@ -85,6 +86,6 @@ export async function attributeToStyle(html = '', attributes = [], posthtmlOptio
|
|
|
85
86
|
return posthtml([
|
|
86
87
|
posthtmlPlugin(attributes)
|
|
87
88
|
])
|
|
88
|
-
.process(html, posthtmlOptions)
|
|
89
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
89
90
|
.then(result => result.html)
|
|
90
91
|
}
|
|
@@ -8,9 +8,7 @@ import { parser as parse } from 'posthtml-parser'
|
|
|
8
8
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
9
9
|
import baseUrl, { parseSrcset, stringifySrcset, defaultTags } from 'posthtml-base-url'
|
|
10
10
|
|
|
11
|
-
const posthtmlOptions =
|
|
12
|
-
|
|
13
|
-
const posthtmlPlugin = url => tree => {
|
|
11
|
+
const posthtmlPlugin = (url, posthtmlOptions = {}) => tree => {
|
|
14
12
|
// Handle `baseURL` as a string
|
|
15
13
|
if (typeof url === 'string' && url.length > 0) {
|
|
16
14
|
const html = rewriteVMLs(render(tree), url)
|
|
@@ -48,11 +46,13 @@ const posthtmlPlugin = url => tree => {
|
|
|
48
46
|
|
|
49
47
|
export default posthtmlPlugin
|
|
50
48
|
|
|
51
|
-
export async function addBaseUrl(html = '', options = {},
|
|
49
|
+
export async function addBaseUrl(html = '', options = {}, posthtmlOptions = {}) {
|
|
50
|
+
posthtmlOptions = getPosthtmlOptions(posthtmlOptions)
|
|
51
|
+
|
|
52
52
|
return posthtml([
|
|
53
|
-
posthtmlPlugin(options)
|
|
53
|
+
posthtmlPlugin(options, posthtmlOptions)
|
|
54
54
|
])
|
|
55
|
-
.process(html,
|
|
55
|
+
.process(html, posthtmlOptions)
|
|
56
56
|
.then(result => result.html)
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -2,6 +2,7 @@ import posthtml from 'posthtml'
|
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
3
|
import posthtmlContent from 'posthtml-content'
|
|
4
4
|
import { filters as defaultFilters } from './defaultFilters.js'
|
|
5
|
+
import { getPosthtmlOptions } from '../../posthtml/defaultConfig.js'
|
|
5
6
|
|
|
6
7
|
export default function posthtmlPlugin(filters = {}) {
|
|
7
8
|
filters = merge(defaultFilters, filters)
|
|
@@ -13,6 +14,6 @@ export async function filters(html = '', filters = {}, posthtmlOptions = {}) {
|
|
|
13
14
|
return posthtml([
|
|
14
15
|
posthtmlPlugin(filters)
|
|
15
16
|
])
|
|
16
|
-
.process(html, posthtmlOptions)
|
|
17
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
17
18
|
.then(result => result.html)
|
|
18
19
|
}
|
|
@@ -21,6 +21,7 @@ import safeClassNames from './safeClassNames.js'
|
|
|
21
21
|
import replaceStrings from './replaceStrings.js'
|
|
22
22
|
import attributeToStyle from './attributeToStyle.js'
|
|
23
23
|
import removeAttributes from './removeAttributes.js'
|
|
24
|
+
import replaceCssProperties from './replaceCssProperties.js'
|
|
24
25
|
|
|
25
26
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
26
27
|
|
|
@@ -37,7 +38,7 @@ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
|
37
38
|
export async function run(html = '', config = {}) {
|
|
38
39
|
const posthtmlPlugins = []
|
|
39
40
|
|
|
40
|
-
const
|
|
41
|
+
const posthtmlOptions = getPosthtmlOptions(get(config, 'posthtml.options', {}))
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* 1. Core transformers
|
|
@@ -60,7 +61,16 @@ export async function run(html = '', config = {}) {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
|
-
* 3.
|
|
64
|
+
* 3. Replace CSS properties
|
|
65
|
+
*
|
|
66
|
+
* Replaces CSS properties based on a custom mapping.
|
|
67
|
+
*/
|
|
68
|
+
if (get(config, 'css.replaceProperties') !== false) {
|
|
69
|
+
posthtmlPlugins.push(replaceCssProperties(config))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 4. Filters
|
|
64
74
|
*
|
|
65
75
|
* Filters are always applied, unless explicitly disabled.
|
|
66
76
|
*/
|
|
@@ -71,7 +81,7 @@ export async function run(html = '', config = {}) {
|
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
/**
|
|
74
|
-
*
|
|
84
|
+
* 5. Markdown
|
|
75
85
|
*
|
|
76
86
|
* Convert Markdown to HTML with markdown-it, unless explicitly disabled.
|
|
77
87
|
*/
|
|
@@ -82,7 +92,7 @@ export async function run(html = '', config = {}) {
|
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
/**
|
|
85
|
-
*
|
|
95
|
+
* 6. Prevent widow words
|
|
86
96
|
*
|
|
87
97
|
* Enabled by default, will prevent widow words in elements
|
|
88
98
|
* wrapped with a `prevent-widows` attribute.
|
|
@@ -94,7 +104,7 @@ export async function run(html = '', config = {}) {
|
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
/**
|
|
97
|
-
*
|
|
107
|
+
* 7. Attribute to `style`
|
|
98
108
|
*
|
|
99
109
|
* Duplicate HTML attributes to inline CSS.
|
|
100
110
|
*/
|
|
@@ -105,23 +115,24 @@ export async function run(html = '', config = {}) {
|
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
/**
|
|
108
|
-
*
|
|
118
|
+
* 8. Inline CSS
|
|
109
119
|
*
|
|
110
120
|
* Inline CSS into HTML.
|
|
111
121
|
*/
|
|
112
122
|
if (get(config, 'css.inline')) {
|
|
113
|
-
posthtmlPlugins.push(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
removeInlinedSelectors: true,
|
|
118
|
-
|
|
123
|
+
posthtmlPlugins.push(
|
|
124
|
+
inlineCSS(
|
|
125
|
+
merge(
|
|
126
|
+
get(config, 'css.inline', {}),
|
|
127
|
+
{ removeInlinedSelectors: true },
|
|
128
|
+
),
|
|
129
|
+
posthtmlOptions
|
|
119
130
|
)
|
|
120
|
-
)
|
|
131
|
+
)
|
|
121
132
|
}
|
|
122
133
|
|
|
123
134
|
/**
|
|
124
|
-
*
|
|
135
|
+
* 9. Remove attributes
|
|
125
136
|
*
|
|
126
137
|
* Remove attributes from HTML tags
|
|
127
138
|
* If `undefined`, removes empty `style` and `class` attributes
|
|
@@ -130,13 +141,13 @@ export async function run(html = '', config = {}) {
|
|
|
130
141
|
posthtmlPlugins.push(
|
|
131
142
|
removeAttributes(
|
|
132
143
|
get(config, 'attributes.remove', []),
|
|
133
|
-
|
|
144
|
+
posthtmlOptions
|
|
134
145
|
)
|
|
135
146
|
)
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
/**
|
|
139
|
-
*
|
|
150
|
+
* 10. Shorthand CSS
|
|
140
151
|
*
|
|
141
152
|
* Convert longhand CSS properties to shorthand in `style` attributes.
|
|
142
153
|
*/
|
|
@@ -147,7 +158,7 @@ export async function run(html = '', config = {}) {
|
|
|
147
158
|
}
|
|
148
159
|
|
|
149
160
|
/**
|
|
150
|
-
*
|
|
161
|
+
* 11. Add attributes
|
|
151
162
|
*
|
|
152
163
|
* Add attributes to HTML tags.
|
|
153
164
|
*/
|
|
@@ -158,19 +169,19 @@ export async function run(html = '', config = {}) {
|
|
|
158
169
|
}
|
|
159
170
|
|
|
160
171
|
/**
|
|
161
|
-
*
|
|
172
|
+
* 12. Base URL
|
|
162
173
|
*
|
|
163
174
|
* Add a base URL to relative paths.
|
|
164
175
|
*/
|
|
165
176
|
const baseConfig = get(config, 'baseURL', get(config, 'baseUrl'))
|
|
166
177
|
if (baseConfig) {
|
|
167
178
|
posthtmlPlugins.push(
|
|
168
|
-
baseUrl(baseConfig)
|
|
179
|
+
baseUrl(baseConfig, posthtmlOptions)
|
|
169
180
|
)
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
/**
|
|
173
|
-
*
|
|
184
|
+
* 13. URL parameters
|
|
174
185
|
*
|
|
175
186
|
* Add parameters to URLs.
|
|
176
187
|
*/
|
|
@@ -181,7 +192,7 @@ export async function run(html = '', config = {}) {
|
|
|
181
192
|
}
|
|
182
193
|
|
|
183
194
|
/**
|
|
184
|
-
*
|
|
195
|
+
* 14. Six-digit HEX
|
|
185
196
|
*
|
|
186
197
|
* Enabled by default, converts three-digit HEX colors to six-digit.
|
|
187
198
|
*/
|
|
@@ -192,7 +203,7 @@ export async function run(html = '', config = {}) {
|
|
|
192
203
|
}
|
|
193
204
|
|
|
194
205
|
/**
|
|
195
|
-
*
|
|
206
|
+
* 15. PostHTML MSO
|
|
196
207
|
*
|
|
197
208
|
* Enabled by default, simplifies writing MSO conditionals for Outlook.
|
|
198
209
|
*/
|
|
@@ -203,23 +214,25 @@ export async function run(html = '', config = {}) {
|
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
/**
|
|
206
|
-
*
|
|
217
|
+
* 16. Purge CSS
|
|
207
218
|
*
|
|
208
219
|
* Remove unused CSS, uglify classes etc.
|
|
209
220
|
*/
|
|
210
221
|
if (get(config, 'css.purge')) {
|
|
211
|
-
posthtmlPlugins.push(
|
|
222
|
+
posthtmlPlugins.push(
|
|
223
|
+
purge(config.css.purge, posthtmlOptions)
|
|
224
|
+
)
|
|
212
225
|
}
|
|
213
226
|
|
|
214
227
|
/**
|
|
215
|
-
*
|
|
228
|
+
* 17. <template> tags
|
|
216
229
|
*
|
|
217
230
|
* Replace <template> tags with their content.
|
|
218
231
|
*/
|
|
219
232
|
posthtmlPlugins.push(templateTag())
|
|
220
233
|
|
|
221
234
|
/**
|
|
222
|
-
*
|
|
235
|
+
* 18. Replace strings
|
|
223
236
|
*
|
|
224
237
|
* Replace strings through regular expressions.
|
|
225
238
|
*/
|
|
@@ -230,29 +243,29 @@ export async function run(html = '', config = {}) {
|
|
|
230
243
|
}
|
|
231
244
|
|
|
232
245
|
/**
|
|
233
|
-
*
|
|
246
|
+
* 19. Prettify
|
|
234
247
|
*
|
|
235
248
|
* Pretty-print HTML using js-beautify.
|
|
236
249
|
*/
|
|
237
250
|
if (get(config, 'prettify')) {
|
|
238
251
|
posthtmlPlugins.push(
|
|
239
|
-
prettify(get(config, 'prettify', {}))
|
|
252
|
+
prettify(get(config, 'prettify', {}), posthtmlOptions)
|
|
240
253
|
)
|
|
241
254
|
}
|
|
242
255
|
|
|
243
256
|
/**
|
|
244
|
-
*
|
|
257
|
+
* 20. Minify
|
|
245
258
|
*
|
|
246
259
|
* Minify HTML using html-crush.
|
|
247
260
|
*/
|
|
248
261
|
if (get(config, 'minify')) {
|
|
249
262
|
posthtmlPlugins.push(
|
|
250
|
-
minify(get(config, 'minify', {}))
|
|
263
|
+
minify(get(config, 'minify', {}), posthtmlOptions)
|
|
251
264
|
)
|
|
252
265
|
}
|
|
253
266
|
|
|
254
267
|
return posthtml(posthtmlPlugins)
|
|
255
|
-
.process(html,
|
|
268
|
+
.process(html, posthtmlOptions)
|
|
256
269
|
.then(result => ({
|
|
257
270
|
html: result.html,
|
|
258
271
|
}))
|
|
@@ -18,8 +18,8 @@ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
|
18
18
|
* @param {*} options `css.inline` object from config
|
|
19
19
|
* @returns {Function} PostHTML tree
|
|
20
20
|
*/
|
|
21
|
-
export default (options = {}) => tree => {
|
|
22
|
-
return inline(render(tree), options).then(html => parse(html,
|
|
21
|
+
export default (options = {}, posthtmlOptions = {}) => tree => {
|
|
22
|
+
return inline(render(tree), options).then(html => parse(html, posthtmlOptions))
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -35,6 +35,8 @@ export async function inline(html = '', options = {}) {
|
|
|
35
35
|
return html
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const posthtmlOptions = getPosthtmlOptions()
|
|
39
|
+
|
|
38
40
|
const removeStyleTags = get(options, 'removeStyleTags', false)
|
|
39
41
|
const css = get(options, 'customCSS', false)
|
|
40
42
|
|
|
@@ -62,7 +64,7 @@ export async function inline(html = '', options = {}) {
|
|
|
62
64
|
'lang', // Fenced code blocks
|
|
63
65
|
'ShadowHTML', // Superhuman
|
|
64
66
|
'spark', // Spark
|
|
65
|
-
'at-', // Safe class names for container queries
|
|
67
|
+
'.at-', // Safe class names for container queries
|
|
66
68
|
],
|
|
67
69
|
])
|
|
68
70
|
|
|
@@ -85,7 +87,7 @@ export async function inline(html = '', options = {}) {
|
|
|
85
87
|
* If customCSS is passed, inline that CSS specifically
|
|
86
88
|
* Otherwise, use Juice's default inlining
|
|
87
89
|
*/
|
|
88
|
-
const tree = parse(html,
|
|
90
|
+
const tree = parse(html, posthtmlOptions)
|
|
89
91
|
tree.match = match
|
|
90
92
|
|
|
91
93
|
/**
|
|
@@ -127,7 +129,7 @@ export async function inline(html = '', options = {}) {
|
|
|
127
129
|
* Remove inlined selectors from the HTML
|
|
128
130
|
*
|
|
129
131
|
*/
|
|
130
|
-
const inlined_tree = parse(inlined_html,
|
|
132
|
+
const inlined_tree = parse(inlined_html, posthtmlOptions)
|
|
131
133
|
inlined_tree.match = match
|
|
132
134
|
|
|
133
135
|
const preservedAtRules = get(options, 'preservedAtRules', ['media'])
|
|
@@ -286,7 +288,7 @@ export async function inline(html = '', options = {}) {
|
|
|
286
288
|
} catch { }
|
|
287
289
|
})
|
|
288
290
|
|
|
289
|
-
const optimized_tree = parse($.html(),
|
|
291
|
+
const optimized_tree = parse($.html(), posthtmlOptions)
|
|
290
292
|
optimized_tree.match = match
|
|
291
293
|
|
|
292
294
|
/**
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import
|
|
2
|
+
import markdownIt from 'posthtml-markdownit'
|
|
3
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Markdown transformer for PostHTML.
|
|
7
|
+
*
|
|
8
|
+
* Exported only for the Maizzle API - internally we use `posthtml-markdownit` directly.
|
|
9
|
+
*
|
|
10
|
+
* @param {String} input Markdown input string
|
|
11
|
+
* @param {Object} options Options for `posthtml-markdownit`
|
|
12
|
+
* @param {Object} posthtmlOptions PostHTML options
|
|
13
|
+
* @returns {Promise<string>} Processed HTML string
|
|
14
|
+
*/
|
|
4
15
|
export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
|
|
5
16
|
/**
|
|
6
17
|
* If no input is provided, return an empty string.
|
|
@@ -10,17 +21,16 @@ export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
|
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
/**
|
|
13
|
-
* Automatically wrap in <md> tag, unless manual mode is enabled.
|
|
14
|
-
*
|
|
15
|
-
* With manual mode, user must wrap the input in a <md> tag.
|
|
24
|
+
* Automatically wrap in <md> tag, unless `manual` mode is enabled.
|
|
25
|
+
* In `manual` mode, user must wrap the input in a <md> tag.
|
|
16
26
|
*
|
|
17
27
|
* https://github.com/posthtml/posthtml-markdownit#usage
|
|
18
28
|
*/
|
|
19
29
|
input = options.manual ? input : `<md>${input}</md>`
|
|
20
30
|
|
|
21
31
|
return posthtml([
|
|
22
|
-
|
|
32
|
+
markdownIt(options)
|
|
23
33
|
])
|
|
24
|
-
.process(input, posthtmlOptions)
|
|
34
|
+
.process(input, getPosthtmlOptions(posthtmlOptions))
|
|
25
35
|
.then(result => result.html)
|
|
26
36
|
}
|
|
@@ -5,22 +5,23 @@ import { render } from 'posthtml-render'
|
|
|
5
5
|
import { parser as parse } from 'posthtml-parser'
|
|
6
6
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
7
7
|
|
|
8
|
-
const posthtmlPlugin = (options = {}) => tree => {
|
|
8
|
+
const posthtmlPlugin = (options = {}, posthtmlOptions = {}) => tree => {
|
|
9
9
|
options = merge(options, {
|
|
10
10
|
removeLineBreaks: true,
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
const posthtmlConfig = getPosthtmlOptions()
|
|
14
13
|
const { result: html } = crush(render(tree), options)
|
|
15
14
|
|
|
16
|
-
return parse(html,
|
|
15
|
+
return parse(html, posthtmlOptions)
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export default posthtmlPlugin
|
|
20
19
|
|
|
21
20
|
export async function minify(html = '', options = {}, posthtmlOptions = {}) {
|
|
21
|
+
posthtmlOptions = getPosthtmlOptions(posthtmlOptions)
|
|
22
|
+
|
|
22
23
|
return posthtml([
|
|
23
|
-
posthtmlPlugin(options)
|
|
24
|
+
posthtmlPlugin(options, posthtmlOptions),
|
|
24
25
|
])
|
|
25
26
|
.process(html, posthtmlOptions)
|
|
26
27
|
.then(result => result.html)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import posthtmlMso from 'posthtml-mso'
|
|
3
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
3
4
|
|
|
4
5
|
export default function posthtmlPlugin(options = {}) {
|
|
5
6
|
return posthtmlMso(options)
|
|
@@ -9,6 +10,6 @@ export async function useMso(html = '', options = {}, posthtmlOptions = {}) {
|
|
|
9
10
|
return posthtml([
|
|
10
11
|
posthtmlPlugin(options)
|
|
11
12
|
])
|
|
12
|
-
.process(html, posthtmlOptions)
|
|
13
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
13
14
|
.then(result => result.html)
|
|
14
15
|
}
|
|
@@ -5,7 +5,7 @@ import { render } from 'posthtml-render'
|
|
|
5
5
|
import { parser as parse } from 'posthtml-parser'
|
|
6
6
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
7
7
|
|
|
8
|
-
const posthtmlPlugin = (options = {}) => tree => {
|
|
8
|
+
const posthtmlPlugin = (options = {}, posthtmlOptions = {}) => tree => {
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
space_around_combinator: true, // Preserve space around CSS selector combinators
|
|
11
11
|
newline_between_rules: false, // Remove empty lines between CSS rules
|
|
@@ -15,14 +15,16 @@ 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), posthtmlOptions)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default posthtmlPlugin
|
|
22
22
|
|
|
23
23
|
export async function prettify(html = '', options = {}, posthtmlOptions = {}) {
|
|
24
|
+
posthtmlOptions = getPosthtmlOptions(posthtmlOptions)
|
|
25
|
+
|
|
24
26
|
return posthtml([
|
|
25
|
-
posthtmlPlugin(options)
|
|
27
|
+
posthtmlPlugin(options, posthtmlOptions)
|
|
26
28
|
])
|
|
27
29
|
.process(html, posthtmlOptions)
|
|
28
30
|
.then(result => result.html)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
-
import posthtmlWidows from 'posthtml-widows'
|
|
3
2
|
import { defu as merge } from 'defu'
|
|
3
|
+
import posthtmlWidows from 'posthtml-widows'
|
|
4
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
4
5
|
|
|
5
6
|
export default function posthtmlPlugin(options = {}) {
|
|
6
7
|
options = merge(options, {
|
|
@@ -32,6 +33,6 @@ export async function preventWidows(html = '', options = {}, posthtmlOptions = {
|
|
|
32
33
|
return posthtml([
|
|
33
34
|
posthtmlPlugin(options)
|
|
34
35
|
])
|
|
35
|
-
.process(html, posthtmlOptions)
|
|
36
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
36
37
|
.then(result => result.html)
|
|
37
38
|
}
|
|
@@ -6,7 +6,7 @@ import { render } from 'posthtml-render'
|
|
|
6
6
|
import { parser as parse } from 'posthtml-parser'
|
|
7
7
|
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
8
8
|
|
|
9
|
-
const posthtmlPlugin = options => tree => {
|
|
9
|
+
const posthtmlPlugin = (options = {}, posthtmlOptions = {}) => tree => {
|
|
10
10
|
const defaultSafelist = [
|
|
11
11
|
'*body*', // Gmail
|
|
12
12
|
'*gmail*', // Gmail
|
|
@@ -26,7 +26,7 @@ const posthtmlPlugin = options => tree => {
|
|
|
26
26
|
'*lang*', // Fenced code blocks
|
|
27
27
|
'*ShadowHTML*', // Superhuman
|
|
28
28
|
'*spark*', // Spark
|
|
29
|
-
'
|
|
29
|
+
'.at-*', // Safe class names for container queries
|
|
30
30
|
]
|
|
31
31
|
|
|
32
32
|
const defaultOptions = {
|
|
@@ -39,17 +39,18 @@ const posthtmlPlugin = options => tree => {
|
|
|
39
39
|
|
|
40
40
|
options = merge(options, defaultOptions)
|
|
41
41
|
|
|
42
|
-
const posthtmlConfig = getPosthtmlOptions()
|
|
43
42
|
const { result: html } = comb(render(tree), options)
|
|
44
43
|
|
|
45
|
-
return parse(html,
|
|
44
|
+
return parse(html, posthtmlOptions)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
export default posthtmlPlugin
|
|
49
48
|
|
|
50
49
|
export async function purge(html = '', pluginOptions = {}, posthtmlOptions = {}) {
|
|
50
|
+
posthtmlOptions = getPosthtmlOptions(posthtmlOptions)
|
|
51
|
+
|
|
51
52
|
return posthtml([
|
|
52
|
-
posthtmlPlugin(pluginOptions)
|
|
53
|
+
posthtmlPlugin(pluginOptions, posthtmlOptions)
|
|
53
54
|
])
|
|
54
55
|
.process(html, posthtmlOptions)
|
|
55
56
|
.then(result => result.html)
|
|
@@ -47,9 +47,11 @@ const posthtmlPlugin = (attributes = [], posthtmlOptions = {}) => tree => {
|
|
|
47
47
|
export default posthtmlPlugin
|
|
48
48
|
|
|
49
49
|
export async function removeAttributes(html = '', attributes = [], posthtmlOptions = {}) {
|
|
50
|
+
posthtmlOptions = getPosthtmlOptions(posthtmlOptions)
|
|
51
|
+
|
|
50
52
|
return posthtml([
|
|
51
|
-
posthtmlPlugin(attributes,
|
|
53
|
+
posthtmlPlugin(attributes, posthtmlOptions)
|
|
52
54
|
])
|
|
53
|
-
.process(html,
|
|
55
|
+
.process(html, posthtmlOptions)
|
|
54
56
|
.then(result => result.html)
|
|
55
57
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import postcss from 'postcss'
|
|
2
|
+
import get from 'lodash-es/get.js'
|
|
3
|
+
import { defu as merge } from 'defu'
|
|
4
|
+
import postcssSafeParser from 'postcss-safe-parser'
|
|
5
|
+
|
|
6
|
+
export default (maizzleConfig => tree => {
|
|
7
|
+
const process = node => {
|
|
8
|
+
if (node?.tag !== 'style') {
|
|
9
|
+
return node
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const replacements = get(maizzleConfig, 'css.replaceProperties', {})
|
|
13
|
+
|
|
14
|
+
if (Object.keys(replacements).length === 0) {
|
|
15
|
+
return node
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const css = Array.isArray(node.content) ? node.content.join('') : node.content
|
|
19
|
+
|
|
20
|
+
postcss([
|
|
21
|
+
postcssPlugin({
|
|
22
|
+
properties: replacements,
|
|
23
|
+
}),
|
|
24
|
+
]).process(css, merge(
|
|
25
|
+
get(maizzleConfig, 'postcss.options', {}),
|
|
26
|
+
{
|
|
27
|
+
from: undefined,
|
|
28
|
+
parser: postcssSafeParser
|
|
29
|
+
}
|
|
30
|
+
)).then( result => {
|
|
31
|
+
node.content = result.css
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return node
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return tree.walk(process)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const postcssPlugin = (opts = {}) => {
|
|
41
|
+
opts = merge(opts, {
|
|
42
|
+
properties: {
|
|
43
|
+
'text-decoration-line': 'text-decoration',
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
postcssPlugin: 'postcss-replace-properties',
|
|
49
|
+
Declaration(decl) {
|
|
50
|
+
if (Object.hasOwn(opts.properties, decl.prop)) {
|
|
51
|
+
decl.prop = opts.properties[decl.prop]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -32,6 +32,6 @@ export async function replaceStrings(html = '', replacements = {}, posthtmlOptio
|
|
|
32
32
|
return posthtml([
|
|
33
33
|
posthtmlPlugin(replacements)
|
|
34
34
|
])
|
|
35
|
-
.process(html, posthtmlOptions)
|
|
35
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
36
36
|
.then(result => result.html)
|
|
37
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { defu as merge } from 'defu'
|
|
3
3
|
import posthtmlSafeClassNames from 'posthtml-safe-class-names'
|
|
4
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
4
5
|
|
|
5
6
|
export default function posthtmlPlugin(options = {}) {
|
|
6
7
|
// If options is boolean, convert to object
|
|
@@ -24,6 +25,6 @@ export async function safeClassNames(html = '', options = {}, posthtmlOptions =
|
|
|
24
25
|
return posthtml([
|
|
25
26
|
posthtmlPlugin(options)
|
|
26
27
|
])
|
|
27
|
-
.process(html, posthtmlOptions)
|
|
28
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
28
29
|
.then(result => result.html)
|
|
29
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
2
3
|
import posthtmlMergeLonghand from 'posthtml-postcss-merge-longhand'
|
|
3
4
|
|
|
4
5
|
export default function posthtmlPlugin(options = {}) {
|
|
@@ -15,6 +16,6 @@ export async function shorthandCSS(html = '', options = {}, posthtmlOptions = {}
|
|
|
15
16
|
return posthtml([
|
|
16
17
|
posthtmlPlugin(options)
|
|
17
18
|
])
|
|
18
|
-
.process(html, posthtmlOptions)
|
|
19
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
19
20
|
.then(result => result.html)
|
|
20
21
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import { conv } from 'color-shorthand-hex-to-six-digit'
|
|
3
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
3
4
|
|
|
4
5
|
const posthtmlPlugin = () => tree => {
|
|
5
6
|
const targets = new Set(['bgcolor', 'color'])
|
|
@@ -25,6 +26,6 @@ export async function sixHEX(html = '', posthtmlOptions = {}) {
|
|
|
25
26
|
return posthtml([
|
|
26
27
|
posthtmlPlugin()
|
|
27
28
|
])
|
|
28
|
-
.process(html, posthtmlOptions)
|
|
29
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
29
30
|
.then(result => result.html)
|
|
30
31
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import posthtml from 'posthtml'
|
|
2
2
|
import get from 'lodash-es/get.js'
|
|
3
3
|
import urlParameters from 'posthtml-url-parameters'
|
|
4
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
4
5
|
|
|
5
6
|
export default function posthtmlPlugin(options = {}) {
|
|
6
7
|
const { _options, ...parameters } = options
|
|
@@ -15,6 +16,6 @@ export async function addURLParams(html = '', options = {}, posthtmlOptions = {}
|
|
|
15
16
|
return posthtml([
|
|
16
17
|
posthtmlPlugin(options)
|
|
17
18
|
])
|
|
18
|
-
.process(html, posthtmlOptions)
|
|
19
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
19
20
|
.then(result => result.html)
|
|
20
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import postcss from 'postcss'
|
|
2
2
|
import posthtml from 'posthtml'
|
|
3
3
|
import get from 'lodash-es/get.js'
|
|
4
|
+
import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
|
|
4
5
|
|
|
5
6
|
const posthtmlPlugin = (mappings = {}) => tree => {
|
|
6
7
|
if (!Object.keys(mappings).length) {
|
|
@@ -58,6 +59,6 @@ export async function useAttributeSizes(html = '', mappings = {}, posthtmlOption
|
|
|
58
59
|
return posthtml([
|
|
59
60
|
posthtmlPlugin(mappings)
|
|
60
61
|
])
|
|
61
|
-
.process(html, posthtmlOptions)
|
|
62
|
+
.process(html, getPosthtmlOptions(posthtmlOptions))
|
|
62
63
|
.then(result => result.html)
|
|
63
64
|
}
|