@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,490 +1,511 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const Maizzle = require('../src')
|
|
3
|
-
const removePlaintextTags = require('../src/transformers/plaintext')
|
|
4
|
-
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
|
|
8
|
-
const readFile = (dir, filename) => fs.promises
|
|
9
|
-
.readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
|
|
10
|
-
.then(html => html.trim())
|
|
11
|
-
|
|
12
|
-
const fixture = file => readFile('fixtures/transformers', file)
|
|
13
|
-
const expected = file => readFile('expected/transformers', file)
|
|
14
|
-
|
|
15
|
-
test('remove inline sizes', async t => {
|
|
16
|
-
const options = {
|
|
17
|
-
width: ['TD'],
|
|
18
|
-
height: ['TD']
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const html = await Maizzle.removeInlineSizes('<td style="width:100%;height:10px;">test</td>', options)
|
|
22
|
-
|
|
23
|
-
t.is(html, '<td style="">test</td>')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('remove inline background-color', async t => {
|
|
27
|
-
const html = await Maizzle.removeInlineBgColor(`<td style="background-color: red" bgcolor="red">test</td>`)
|
|
28
|
-
const html2 = await Maizzle.removeInlineBgColor(
|
|
29
|
-
`<td style="background-color: red" bgcolor="red">test</td>`,
|
|
30
|
-
{
|
|
31
|
-
inlineCSS: {
|
|
32
|
-
preferBgColorAttribute: true
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
t.is(html, '<td style="" bgcolor="red">test</td>')
|
|
38
|
-
t.is(html2, '<td style="" bgcolor="red">test</td>')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('remove inline background-color (with tags)', async t => {
|
|
42
|
-
const html = await Maizzle.removeInlineBgColor(
|
|
43
|
-
`<table style="background-color: red"><tr><td style="background-color: red">test</td></tr></table>`,
|
|
44
|
-
['table']
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
t.is(html, '<table style="" bgcolor="red"><tr><td style="background-color: red">test</td></tr></table>')
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('inline CSS', async t => {
|
|
51
|
-
const html = `<div class="foo bar
|
|
52
|
-
const css = `
|
|
53
|
-
.foo {color: red}
|
|
54
|
-
.bar {cursor: pointer}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
<html>
|
|
104
|
-
<head>
|
|
105
|
-
<style>
|
|
106
|
-
.foo {color: red}
|
|
107
|
-
.bar-baz {color: blue}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const html = await Maizzle.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
<
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
t.is(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
.
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
color:
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const Maizzle = require('../src')
|
|
3
|
+
const removePlaintextTags = require('../src/transformers/plaintext')
|
|
4
|
+
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
|
|
8
|
+
const readFile = (dir, filename) => fs.promises
|
|
9
|
+
.readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
|
|
10
|
+
.then(html => html.trim())
|
|
11
|
+
|
|
12
|
+
const fixture = file => readFile('fixtures/transformers', file)
|
|
13
|
+
const expected = file => readFile('expected/transformers', file)
|
|
14
|
+
|
|
15
|
+
test('remove inline sizes', async t => {
|
|
16
|
+
const options = {
|
|
17
|
+
width: ['TD'],
|
|
18
|
+
height: ['TD']
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const html = await Maizzle.removeInlineSizes('<td style="width:100%;height:10px;">test</td>', options)
|
|
22
|
+
|
|
23
|
+
t.is(html, '<td style="">test</td>')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('remove inline background-color', async t => {
|
|
27
|
+
const html = await Maizzle.removeInlineBgColor(`<td style="background-color: red" bgcolor="red">test</td>`)
|
|
28
|
+
const html2 = await Maizzle.removeInlineBgColor(
|
|
29
|
+
`<td style="background-color: red" bgcolor="red">test</td>`,
|
|
30
|
+
{
|
|
31
|
+
inlineCSS: {
|
|
32
|
+
preferBgColorAttribute: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
t.is(html, '<td style="" bgcolor="red">test</td>')
|
|
38
|
+
t.is(html2, '<td style="" bgcolor="red">test</td>')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('remove inline background-color (with tags)', async t => {
|
|
42
|
+
const html = await Maizzle.removeInlineBgColor(
|
|
43
|
+
`<table style="background-color: red"><tr><td style="background-color: red">test</td></tr></table>`,
|
|
44
|
+
['table']
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
t.is(html, '<table style="" bgcolor="red"><tr><td style="background-color: red">test</td></tr></table>')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('inline CSS', async t => {
|
|
51
|
+
const html = `<div class="foo bar">test</div>`
|
|
52
|
+
const css = `
|
|
53
|
+
.foo {color: red}
|
|
54
|
+
.bar {cursor: pointer}
|
|
55
|
+
`
|
|
56
|
+
|
|
57
|
+
const result = await Maizzle.inlineCSS(html, {
|
|
58
|
+
customCSS: css,
|
|
59
|
+
removeStyleTags: false,
|
|
60
|
+
styleToAttribute: {
|
|
61
|
+
'text-align': 'align'
|
|
62
|
+
},
|
|
63
|
+
applyWidthAttributes: ['TABLE'],
|
|
64
|
+
applyHeightAttributes: ['TD'],
|
|
65
|
+
mergeLonghand: ['div'],
|
|
66
|
+
excludedProperties: ['cursor'],
|
|
67
|
+
codeBlocks: {
|
|
68
|
+
RB: {
|
|
69
|
+
start: '<%',
|
|
70
|
+
end: '%>'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
t.is(result, '<div class="foo bar" style="color: red;">test</div>')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('inline CSS (disabled)', async t => {
|
|
79
|
+
const html = `<div class="foo">test</div>`
|
|
80
|
+
const css = `.foo {color: red}`
|
|
81
|
+
|
|
82
|
+
const result = await Maizzle.inlineCSS(html, {inlineCSS: false, customCSS: css})
|
|
83
|
+
|
|
84
|
+
t.is(result, '<div class="foo">test</div>')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('remove unused CSS', async t => {
|
|
88
|
+
const html = `<!DOCTYPE html>
|
|
89
|
+
<html>
|
|
90
|
+
<head>
|
|
91
|
+
<style>
|
|
92
|
+
.foo {color: red}
|
|
93
|
+
.bar-baz {color: blue}
|
|
94
|
+
.baz {color: white}
|
|
95
|
+
</style>
|
|
96
|
+
</head>
|
|
97
|
+
<body>
|
|
98
|
+
<div class="foo">test div with some text</div>
|
|
99
|
+
</body>
|
|
100
|
+
</html>`
|
|
101
|
+
|
|
102
|
+
const result1 = `<!DOCTYPE html>
|
|
103
|
+
<html>
|
|
104
|
+
<head>
|
|
105
|
+
<style>
|
|
106
|
+
.foo {color: red}
|
|
107
|
+
.bar-baz {color: blue}
|
|
108
|
+
</style>
|
|
109
|
+
</head>
|
|
110
|
+
<body>
|
|
111
|
+
<div class="foo">test div with some text</div>
|
|
112
|
+
</body>
|
|
113
|
+
</html>`
|
|
114
|
+
|
|
115
|
+
const result2 = `<!DOCTYPE html>
|
|
116
|
+
<html>
|
|
117
|
+
<head>
|
|
118
|
+
<style>
|
|
119
|
+
.foo {color: red}
|
|
120
|
+
</style>
|
|
121
|
+
</head>
|
|
122
|
+
<body>
|
|
123
|
+
<div class="foo">test div with some text</div>
|
|
124
|
+
</body>
|
|
125
|
+
</html>`
|
|
126
|
+
|
|
127
|
+
const withOptions = await Maizzle.removeUnusedCSS(html, {whitelist: ['.bar*']})
|
|
128
|
+
const enabled = await Maizzle.removeUnusedCSS(html, true)
|
|
129
|
+
|
|
130
|
+
t.is(withOptions, result1)
|
|
131
|
+
t.is(enabled, result2)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('remove unused CSS (disabled)', async t => {
|
|
135
|
+
const html = `<!DOCTYPE html>
|
|
136
|
+
<html>
|
|
137
|
+
<head>
|
|
138
|
+
<style>
|
|
139
|
+
.foo {color: red}
|
|
140
|
+
</style>
|
|
141
|
+
</head>
|
|
142
|
+
<body>
|
|
143
|
+
<div class="foo">test div with some text</div>
|
|
144
|
+
</body>
|
|
145
|
+
</html>`
|
|
146
|
+
|
|
147
|
+
const result = `<!DOCTYPE html>
|
|
148
|
+
<html>
|
|
149
|
+
<head>
|
|
150
|
+
<style>
|
|
151
|
+
.foo {color: red}
|
|
152
|
+
</style>
|
|
153
|
+
</head>
|
|
154
|
+
<body>
|
|
155
|
+
<div class="foo">test div with some text</div>
|
|
156
|
+
</body>
|
|
157
|
+
</html>`
|
|
158
|
+
|
|
159
|
+
const disabled = await Maizzle.removeUnusedCSS(html, {removeUnusedCSS: false})
|
|
160
|
+
const unset = await Maizzle.removeUnusedCSS(html)
|
|
161
|
+
|
|
162
|
+
t.is(disabled, result)
|
|
163
|
+
t.is(unset, result)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('remove attributes', async t => {
|
|
167
|
+
const html = await Maizzle.removeAttributes(`<div style="" role="article"></div>`, [{name: 'role', value: 'article'}])
|
|
168
|
+
|
|
169
|
+
t.is(html, '<div></div>')
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('extra attributes', async t => {
|
|
173
|
+
const html = await Maizzle.applyExtraAttributes('<div />', {div: {role: 'article'}})
|
|
174
|
+
|
|
175
|
+
t.is(html, '<div role="article"></div>')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('extra attributes (disabled)', async t => {
|
|
179
|
+
const html = await Maizzle.applyExtraAttributes('<img src="example.jpg">', {extraAttributes: false})
|
|
180
|
+
|
|
181
|
+
t.is(html, '<img src="example.jpg">')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('base URL (string)', async t => {
|
|
185
|
+
const source = await fixture('base-url')
|
|
186
|
+
const html = await Maizzle.applyBaseUrl(source, 'https://example.com/')
|
|
187
|
+
|
|
188
|
+
t.is(html, await expected('base-url'))
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('base URL (object)', async t => {
|
|
192
|
+
const source = await fixture('base-url')
|
|
193
|
+
const html = await Maizzle.applyBaseUrl(source, {
|
|
194
|
+
url: 'https://example.com/',
|
|
195
|
+
allTags: true,
|
|
196
|
+
styleTag: true,
|
|
197
|
+
inlineCss: true
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
t.is(html, await expected('base-url'))
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('prettify', async t => {
|
|
204
|
+
// `prettify: true`
|
|
205
|
+
const html2 = await Maizzle.prettify('<div><p>test</p></div>', true)
|
|
206
|
+
|
|
207
|
+
// With custom object config
|
|
208
|
+
// eslint-disable-next-line
|
|
209
|
+
const html = await Maizzle.prettify('<div><p>test</p></div>', {indent_inner_result: true})
|
|
210
|
+
|
|
211
|
+
// No config
|
|
212
|
+
const html3 = await Maizzle.prettify('<div><p>test</p></div>')
|
|
213
|
+
|
|
214
|
+
// Empty object config
|
|
215
|
+
const html4 = await Maizzle.prettify('<div><p>test</p></div>', {})
|
|
216
|
+
|
|
217
|
+
t.is(html, '<div>\n <p>test</p>\n</div>')
|
|
218
|
+
t.is(html2, '<div>\n <p>test</p>\n</div>')
|
|
219
|
+
t.is(html3, '<div><p>test</p></div>')
|
|
220
|
+
t.is(html4, '<div><p>test</p></div>')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
test('minify', async t => {
|
|
224
|
+
const html = await Maizzle.minify('<div>\n\n<p>\n\ntest</p></div>', {lineLengthLimit: 10})
|
|
225
|
+
|
|
226
|
+
t.is(html, '<div><p>\ntest</p>\n</div>')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test('minify (disabled)', async t => {
|
|
230
|
+
const html = await Maizzle.minify('<div>\n\n<p>\n\ntest</p></div>', {minify: false})
|
|
231
|
+
|
|
232
|
+
t.is(html, '<div>\n\n<p>\n\ntest</p></div>')
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('removes plaintext tag', t => {
|
|
236
|
+
let html = removePlaintextTags('<plaintext>Removed</plaintext><div>Preserved</div>')
|
|
237
|
+
html = html.replace(/[^\S\r\n]+$/gm, '').trim()
|
|
238
|
+
|
|
239
|
+
t.is(html, '<div>Preserved</div>')
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('replace strings', async t => {
|
|
243
|
+
const html = await Maizzle.replaceStrings('initial text', {initial: 'updated'})
|
|
244
|
+
|
|
245
|
+
t.is(html, 'updated text')
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
test('safe class names', async t => {
|
|
249
|
+
const html = await Maizzle.safeClassNames('<div class="sm:text-left w-1.5">foo</div>', {'.': '_dot_'})
|
|
250
|
+
|
|
251
|
+
t.is(html, '<div class="sm-text-left w-1_dot_5">foo</div>')
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
test('safe class names (disabled)', async t => {
|
|
255
|
+
const html = await Maizzle.safeClassNames('<div class="sm:text-left">foo</div>', {safeClassNames: false})
|
|
256
|
+
|
|
257
|
+
t.is(html, '<div class="sm:text-left">foo</div>')
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
test('six digit hex', async t => {
|
|
261
|
+
const html = await Maizzle.ensureSixHEX(
|
|
262
|
+
`
|
|
263
|
+
<div bgcolor="#000" style="color: #fff; background-color: #000">This should not change: #ffc</div>
|
|
264
|
+
<font color="#fff">Text</font>
|
|
265
|
+
`)
|
|
266
|
+
|
|
267
|
+
t.is(
|
|
268
|
+
html.trim(),
|
|
269
|
+
`
|
|
270
|
+
<div bgcolor="#000000" style="color: #fff; background-color: #000">This should not change: #ffc</div>
|
|
271
|
+
<font color="#ffffff">Text</font>
|
|
272
|
+
`.trim()
|
|
273
|
+
)
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
test('six digit hex (disabled)', async t => {
|
|
277
|
+
const html = await Maizzle.ensureSixHEX('<td style="color: #ffc" bgcolor="#000"></td>', {sixHex: false})
|
|
278
|
+
|
|
279
|
+
t.is(html, '<td style="color: #ffc" bgcolor="#000"></td>')
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
test('filters (default)', async t => {
|
|
283
|
+
const source = await fixture('filters')
|
|
284
|
+
const html = await Maizzle.withFilters(source)
|
|
285
|
+
|
|
286
|
+
t.is(html, await expected('filters'))
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
test('filters (tailwindcss)', async t => {
|
|
290
|
+
const html = await Maizzle.withFilters(
|
|
291
|
+
`<style tailwindcss>
|
|
292
|
+
div {
|
|
293
|
+
@apply hidden;
|
|
294
|
+
}
|
|
295
|
+
</style>`
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
const expected = `<style>.inline { display: inline !important
|
|
299
|
+
} .table { display: table !important
|
|
300
|
+
} .contents { display: contents !important
|
|
301
|
+
} .hidden { display: none !important
|
|
302
|
+
} .truncate { overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important
|
|
303
|
+
} .uppercase { text-transform: uppercase !important
|
|
304
|
+
} .lowercase { text-transform: lowercase !important
|
|
305
|
+
} .capitalize { text-transform: capitalize !important
|
|
306
|
+
} div { display: none
|
|
307
|
+
}
|
|
308
|
+
</style>`
|
|
309
|
+
|
|
310
|
+
t.is(html, expected)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('filters (postcss)', async t => {
|
|
314
|
+
const html = await Maizzle.withFilters(
|
|
315
|
+
`<style postcss>@import 'test/stubs/post.css';</style>`
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
const expected = `<style>div {
|
|
319
|
+
margin: 1px 2px 3px 4px;
|
|
320
|
+
}</style>`
|
|
321
|
+
|
|
322
|
+
t.is(html, expected)
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
test('url parameters', async t => {
|
|
326
|
+
const html = await Maizzle.addURLParams('<a href="https://example.com">test</a>', {bar: 'baz', qix: 'qux'})
|
|
327
|
+
|
|
328
|
+
t.is(html, '<a href="https://example.com?bar=baz&qix=qux">test</a>')
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
test('attribute to style', async t => {
|
|
332
|
+
const html = `<table width="100%" height="600" align="left" bgcolor="#FFFFFF" background="https://example.com/image.jpg">
|
|
333
|
+
<tr>
|
|
334
|
+
<td align="center" valign="top"></td>
|
|
335
|
+
</tr>
|
|
336
|
+
</table>`
|
|
337
|
+
|
|
338
|
+
const expected = `<table width="100%" height="600" align="left" bgcolor="#FFFFFF" background="https://example.com/image.jpg" style="width: 100%; height: 600px; float: left; background-color: #FFFFFF; background-image: url('https://example.com/image.jpg')">
|
|
339
|
+
<tr style="">
|
|
340
|
+
<td align="center" valign="top" style="text-align: center; vertical-align: top"></td>
|
|
341
|
+
</tr>
|
|
342
|
+
</table>`
|
|
343
|
+
|
|
344
|
+
const html2 = `<table align="center">
|
|
345
|
+
<tr>
|
|
346
|
+
<td></td>
|
|
347
|
+
</tr>
|
|
348
|
+
</table>`
|
|
349
|
+
|
|
350
|
+
const expected2 = `<table align="center" style="margin-left: auto; margin-right: auto">
|
|
351
|
+
<tr style="">
|
|
352
|
+
<td style=""></td>
|
|
353
|
+
</tr>
|
|
354
|
+
</table>`
|
|
355
|
+
|
|
356
|
+
const withArray = await Maizzle.attributeToStyle(html, ['width', 'height', 'bgcolor', 'background', 'align', 'valign'])
|
|
357
|
+
const withOptionBoolean = await Maizzle.attributeToStyle(html2, {inlineCSS: {attributeToStyle: true}})
|
|
358
|
+
const withOptionArray = await Maizzle.attributeToStyle(html2, {inlineCSS: {attributeToStyle: ['align']}})
|
|
359
|
+
|
|
360
|
+
t.is(withArray, expected)
|
|
361
|
+
t.is(withOptionBoolean, expected2)
|
|
362
|
+
t.is(withOptionArray, expected2)
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
test('prevent widows', async t => {
|
|
366
|
+
const html = await Maizzle.preventWidows('lorem ipsum dolor')
|
|
367
|
+
|
|
368
|
+
t.is(html, 'lorem ipsum dolor')
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
test('markdown (disabled)', async t => {
|
|
372
|
+
const html = await Maizzle.markdown('> a quote', {markdown: false})
|
|
373
|
+
|
|
374
|
+
t.is(html, '> a quote')
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
test('remove inlined selectors', async t => {
|
|
378
|
+
const html = `<!DOCTYPE html>
|
|
379
|
+
<html>
|
|
380
|
+
<head>
|
|
381
|
+
<style>
|
|
382
|
+
img {
|
|
383
|
+
border: 0;
|
|
384
|
+
vertical-align: middle
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.hover-text-blue:hover {
|
|
388
|
+
color: #00a8ff;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.m-0 {margin: 0}
|
|
392
|
+
|
|
393
|
+
.mb-4 {margin-bottom: 16px}
|
|
394
|
+
|
|
395
|
+
.mt-0 {margin-top: 0}
|
|
396
|
+
|
|
397
|
+
.remove {color: red}
|
|
398
|
+
|
|
399
|
+
[data-ogsc] .hidden {display: none}
|
|
400
|
+
|
|
401
|
+
#keepId {float:none}
|
|
402
|
+
|
|
403
|
+
@media (max-width: 600px) {
|
|
404
|
+
.ignore {color: blue}
|
|
405
|
+
}
|
|
406
|
+
</style>
|
|
407
|
+
<style>
|
|
408
|
+
.keep {margin: 0}
|
|
409
|
+
</style>
|
|
410
|
+
</head>
|
|
411
|
+
<body>
|
|
412
|
+
<div id="keepId" class="remove keep ignore" style="color: red; display: inline">
|
|
413
|
+
<h1 class="m-0 mb-4 mt-0 hover-text-blue" style="margin: 0 0 16px;">Title</h1>
|
|
414
|
+
<img src="https://example.com/image.jpg" style="border: 0; vertical-align: middle">
|
|
415
|
+
<div id="keepId" class="remove keep ignore" style="color: red; display: inline">text</div>
|
|
416
|
+
</div>
|
|
417
|
+
</body>
|
|
418
|
+
</html>`
|
|
419
|
+
|
|
420
|
+
const expected = `<!DOCTYPE html>
|
|
421
|
+
<html>
|
|
422
|
+
<head>
|
|
423
|
+
<style>
|
|
424
|
+
.hover-text-blue:hover {
|
|
425
|
+
color: #00a8ff;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
[data-ogsc] .hidden {display: none}
|
|
429
|
+
|
|
430
|
+
#keepId {float:none}
|
|
431
|
+
|
|
432
|
+
@media (max-width: 600px) {
|
|
433
|
+
.ignore {color: blue}
|
|
434
|
+
}
|
|
435
|
+
</style>
|
|
436
|
+
<style>
|
|
437
|
+
.keep {margin: 0}
|
|
438
|
+
</style>
|
|
439
|
+
</head>
|
|
440
|
+
<body>
|
|
441
|
+
<div id="keepId" class="keep ignore" style="color: red; display: inline">
|
|
442
|
+
<h1 class="hover-text-blue" style="margin: 0 0 16px">Title</h1>
|
|
443
|
+
<img src="https://example.com/image.jpg" style="border: 0; vertical-align: middle">
|
|
444
|
+
<div id="keepId" class="keep ignore" style="color: red; display: inline">text</div>
|
|
445
|
+
</div>
|
|
446
|
+
</body>
|
|
447
|
+
</html>`
|
|
448
|
+
|
|
449
|
+
const result = await Maizzle.removeInlinedClasses(html)
|
|
450
|
+
|
|
451
|
+
t.is(result, expected)
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
test('remove inlined selectors (disabled)', async t => {
|
|
455
|
+
const html = `<!DOCTYPE html>
|
|
456
|
+
<html>
|
|
457
|
+
<head>
|
|
458
|
+
<style>
|
|
459
|
+
.remove {color: red}
|
|
460
|
+
</style>
|
|
461
|
+
</head>
|
|
462
|
+
<body>
|
|
463
|
+
<div class="remove" style="color: red"></div>
|
|
464
|
+
</body>
|
|
465
|
+
</html>`
|
|
466
|
+
|
|
467
|
+
const expected = `<!DOCTYPE html>
|
|
468
|
+
<html>
|
|
469
|
+
<head>
|
|
470
|
+
<style>
|
|
471
|
+
.remove {color: red}
|
|
472
|
+
</style>
|
|
473
|
+
</head>
|
|
474
|
+
<body>
|
|
475
|
+
<div class="remove" style="color: red"></div>
|
|
476
|
+
</body>
|
|
477
|
+
</html>`
|
|
478
|
+
|
|
479
|
+
const result = await Maizzle.removeInlinedClasses(html, {removeInlinedClasses: false})
|
|
480
|
+
|
|
481
|
+
t.is(result, expected)
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
test('shorthand inline css', async t => {
|
|
485
|
+
const html = `
|
|
486
|
+
<div style="padding-left: 2px; padding-right: 2px; padding-top: 2px; padding-bottom: 2px;">padding</div>
|
|
487
|
+
<div style="margin-left: 2px; margin-right: 2px; margin-top: 2px; margin-bottom: 2px;">margin</div>
|
|
488
|
+
<div style="border-width: 1px; border-style: solid; border-color: #000;">border</div>
|
|
489
|
+
<p style="border-width: 1px; border-style: solid; border-color: #000;">border</p>
|
|
490
|
+
`
|
|
491
|
+
|
|
492
|
+
const expect = `
|
|
493
|
+
<div style="padding: 2px;">padding</div>
|
|
494
|
+
<div style="margin: 2px;">margin</div>
|
|
495
|
+
<div style="border: 1px solid #000;">border</div>
|
|
496
|
+
<p style="border: 1px solid #000;">border</p>
|
|
497
|
+
`
|
|
498
|
+
|
|
499
|
+
const expect2 = `
|
|
500
|
+
<div style="padding: 2px;">padding</div>
|
|
501
|
+
<div style="margin: 2px;">margin</div>
|
|
502
|
+
<div style="border: 1px solid #000;">border</div>
|
|
503
|
+
<p style="border-width: 1px; border-style: solid; border-color: #000;">border</p>
|
|
504
|
+
`
|
|
505
|
+
|
|
506
|
+
const result = await Maizzle.shorthandInlineCSS(html)
|
|
507
|
+
const result2 = await Maizzle.shorthandInlineCSS(html, {tags: ['div']})
|
|
508
|
+
|
|
509
|
+
t.is(result, expect)
|
|
510
|
+
t.is(result2, expect2)
|
|
511
|
+
})
|