@maizzle/framework 4.0.0-alpha.8 → 4.0.1
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 -0
- package/package.json +91 -87
- package/src/commands/serve.js +15 -5
- 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 +67 -71
- package/src/generators/postcss.js +29 -29
- package/src/generators/posthtml.js +66 -66
- package/src/generators/tailwindcss.js +116 -116
- package/src/index.js +17 -17
- package/src/transformers/attributeToStyle.js +90 -90
- package/src/transformers/baseUrl.js +69 -45
- package/src/transformers/extraAttributes.js +26 -26
- package/src/transformers/filters/defaultFilters.js +126 -0
- package/src/transformers/{transform.js → filters/index.js} +55 -51
- 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 +27 -20
- 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/removeInlinedSelectors.js +70 -71
- package/src/transformers/removeUnusedCss.js +40 -35
- 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 +13 -13
- 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 +2 -1
- 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 +12 -3
- package/test/expected/useConfig.html +9 -9
- package/test/fixtures/basic.html +6 -6
- package/test/fixtures/posthtml/component.html +19 -19
- 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-image-url.html → base-url.html} +18 -2
- package/test/fixtures/transformers/filters.html +87 -0
- package/test/fixtures/useConfig.html +9 -9
- package/test/stubs/assets/foo.bar +1 -1
- package/test/stubs/breaking/bad.html +5 -5
- package/test/stubs/components/component.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/stubs/templates/1.html +1 -1
- package/test/stubs/templates/2.test +1 -0
- package/test/test-config.js +19 -19
- package/test/test-postcss.js +8 -8
- package/test/test-posthtml.js +72 -66
- package/test/test-tailwindcss.js +117 -117
- package/test/test-todisk.js +42 -28
- package/test/test-tostring.js +148 -142
- package/test/test-transformers.js +78 -46
- package/xo.config.js +22 -22
- package/test/stubs/templates/2.html +0 -1
- package/test/stubs/templates/3.mzl +0 -1
package/test/test-tostring.js
CHANGED
|
@@ -1,142 +1,148 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const Maizzle = require('../src')
|
|
3
|
-
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const Maizzle = require('../src')
|
|
3
|
+
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
|
|
7
|
+
const readFile = (dir, filename) => fs.promises
|
|
8
|
+
.readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
|
|
9
|
+
.then(html => html.trim())
|
|
10
|
+
|
|
11
|
+
const fixture = file => readFile('fixtures', file)
|
|
12
|
+
const expected = file => readFile('expected', file)
|
|
13
|
+
|
|
14
|
+
const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
|
|
15
|
+
|
|
16
|
+
test('compiles HTML string if no options are passed', async t => {
|
|
17
|
+
const source = await fixture('basic')
|
|
18
|
+
|
|
19
|
+
const html = await renderString(source)
|
|
20
|
+
|
|
21
|
+
t.is(html, source)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('uses environment config file(s) if available', async t => {
|
|
25
|
+
const source = await fixture('useConfig')
|
|
26
|
+
|
|
27
|
+
const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
|
|
28
|
+
|
|
29
|
+
t.is(html, await expected('useConfig'))
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('throws if first argument is not an HTML string', async t => {
|
|
33
|
+
await t.throwsAsync(async () => {
|
|
34
|
+
await renderString()
|
|
35
|
+
}, {instanceOf: TypeError, message: 'first argument must be an HTML string, received undefined'})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('throws if first argument is an empty string', async t => {
|
|
39
|
+
await t.throwsAsync(async () => {
|
|
40
|
+
await renderString('')
|
|
41
|
+
}, {instanceOf: RangeError, message: 'received empty string'})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('runs the `beforeRender` event', async t => {
|
|
45
|
+
const html = await renderString(`<div>{{ page.foo }}</div>`, {
|
|
46
|
+
beforeRender(html, config) {
|
|
47
|
+
config.foo = 'bar'
|
|
48
|
+
|
|
49
|
+
return html
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
t.is(html, `<div>bar</div>`)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('runs the `afterRender` event', async t => {
|
|
57
|
+
const result = await renderString(`<div>foo</div>`, {
|
|
58
|
+
afterRender(html, config) {
|
|
59
|
+
config.replaceStrings = {
|
|
60
|
+
foo: 'baz'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return html
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
t.is(result, `<div>baz</div>`)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('runs the `afterTransformers` event', async t => {
|
|
71
|
+
const result = await renderString(`<div>foo</div>`, {
|
|
72
|
+
maizzle: {
|
|
73
|
+
title: 'bar'
|
|
74
|
+
},
|
|
75
|
+
afterTransformers(html, config) {
|
|
76
|
+
return html.replace('foo', config.title)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
t.is(result, `<div>bar</div>`)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('locals work when defined in all supported places', async t => {
|
|
84
|
+
const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
|
|
85
|
+
maizzle: {
|
|
86
|
+
one: 1,
|
|
87
|
+
build: {
|
|
88
|
+
posthtml: {
|
|
89
|
+
expressions: {
|
|
90
|
+
locals: {
|
|
91
|
+
two: 2
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
locals: {
|
|
97
|
+
three: 3
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
t.is(result, `1, 2, 3`)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('prevents overwriting page object', async t => {
|
|
106
|
+
const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
|
|
107
|
+
maizzle: {
|
|
108
|
+
one: 1,
|
|
109
|
+
build: {
|
|
110
|
+
posthtml: {
|
|
111
|
+
expressions: {
|
|
112
|
+
locals: {
|
|
113
|
+
page: {
|
|
114
|
+
two: 2
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
locals: {
|
|
121
|
+
page: {
|
|
122
|
+
three: 3
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
t.is(result, `1, undefined, undefined`)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('preserves css in marked style tags (tailwindcss)', async t => {
|
|
132
|
+
const source = await fixture('transformers/preserve-transform-css')
|
|
133
|
+
const html = await renderString(source, {
|
|
134
|
+
// So that we don't compile twice
|
|
135
|
+
tailwind: {
|
|
136
|
+
compiled: ''
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
t.is(html, await expected('transformers/preserve-transform-css'))
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('@import css files in marked style tags', async t => {
|
|
144
|
+
const source = await fixture('transformers/atimport-in-style')
|
|
145
|
+
const html = await renderString(source)
|
|
146
|
+
|
|
147
|
+
t.is(html, await expected('transformers/atimport-in-style'))
|
|
148
|
+
})
|
|
@@ -3,10 +3,14 @@ const Maizzle = require('../src')
|
|
|
3
3
|
const removePlaintextTags = require('../src/transformers/plaintext')
|
|
4
4
|
|
|
5
5
|
const path = require('path')
|
|
6
|
-
const
|
|
6
|
+
const fs = require('fs')
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
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)
|
|
10
14
|
|
|
11
15
|
test('remove inline sizes', async t => {
|
|
12
16
|
const options = {
|
|
@@ -44,18 +48,10 @@ test('remove inline background-color (with tags)', async t => {
|
|
|
44
48
|
})
|
|
45
49
|
|
|
46
50
|
test('inline CSS', async t => {
|
|
47
|
-
const html = `<div class="foo bar
|
|
51
|
+
const html = `<div class="foo bar">test</div>`
|
|
48
52
|
const css = `
|
|
49
53
|
.foo {color: red}
|
|
50
54
|
.bar {cursor: pointer}
|
|
51
|
-
.px-2 {
|
|
52
|
-
padding-left: 2px;
|
|
53
|
-
padding-right: 2px;
|
|
54
|
-
}
|
|
55
|
-
.py-2 {
|
|
56
|
-
padding-top: 2px;
|
|
57
|
-
padding-bottom: 2px;
|
|
58
|
-
}
|
|
59
55
|
`
|
|
60
56
|
|
|
61
57
|
const result = await Maizzle.inlineCSS(html, {
|
|
@@ -76,13 +72,7 @@ test('inline CSS', async t => {
|
|
|
76
72
|
}
|
|
77
73
|
})
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
customCSS: css,
|
|
81
|
-
mergeLonghand: true
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
t.is(result, '<div class="foo bar px-2 py-2" style="color: red; padding: 2px;">test</div>')
|
|
85
|
-
t.is(result2, '<div class="foo bar px-2 py-2" style="color: red; cursor: pointer; padding: 2px;">test</div>')
|
|
75
|
+
t.is(result, '<div class="foo bar" style="color: red;">test</div>')
|
|
86
76
|
})
|
|
87
77
|
|
|
88
78
|
test('inline CSS (disabled)', async t => {
|
|
@@ -109,7 +99,7 @@ test('remove unused CSS', async t => {
|
|
|
109
99
|
</body>
|
|
110
100
|
</html>`
|
|
111
101
|
|
|
112
|
-
const
|
|
102
|
+
const result1 = `<!DOCTYPE html>
|
|
113
103
|
<html>
|
|
114
104
|
<head>
|
|
115
105
|
<style>
|
|
@@ -122,7 +112,7 @@ test('remove unused CSS', async t => {
|
|
|
122
112
|
</body>
|
|
123
113
|
</html>`
|
|
124
114
|
|
|
125
|
-
const
|
|
115
|
+
const result2 = `<!DOCTYPE html>
|
|
126
116
|
<html>
|
|
127
117
|
<head>
|
|
128
118
|
<style>
|
|
@@ -137,8 +127,8 @@ test('remove unused CSS', async t => {
|
|
|
137
127
|
const withOptions = await Maizzle.removeUnusedCSS(html, {whitelist: ['.bar*']})
|
|
138
128
|
const enabled = await Maizzle.removeUnusedCSS(html, true)
|
|
139
129
|
|
|
140
|
-
t.is(withOptions,
|
|
141
|
-
t.is(enabled,
|
|
130
|
+
t.is(withOptions, result1)
|
|
131
|
+
t.is(enabled, result2)
|
|
142
132
|
})
|
|
143
133
|
|
|
144
134
|
test('remove unused CSS (disabled)', async t => {
|
|
@@ -154,7 +144,7 @@ test('remove unused CSS (disabled)', async t => {
|
|
|
154
144
|
</body>
|
|
155
145
|
</html>`
|
|
156
146
|
|
|
157
|
-
const
|
|
147
|
+
const result = `<!DOCTYPE html>
|
|
158
148
|
<html>
|
|
159
149
|
<head>
|
|
160
150
|
<style>
|
|
@@ -169,8 +159,8 @@ test('remove unused CSS (disabled)', async t => {
|
|
|
169
159
|
const disabled = await Maizzle.removeUnusedCSS(html, {removeUnusedCSS: false})
|
|
170
160
|
const unset = await Maizzle.removeUnusedCSS(html)
|
|
171
161
|
|
|
172
|
-
t.is(disabled,
|
|
173
|
-
t.is(unset,
|
|
162
|
+
t.is(disabled, result)
|
|
163
|
+
t.is(unset, result)
|
|
174
164
|
})
|
|
175
165
|
|
|
176
166
|
test('remove attributes', async t => {
|
|
@@ -192,35 +182,42 @@ test('extra attributes (disabled)', async t => {
|
|
|
192
182
|
})
|
|
193
183
|
|
|
194
184
|
test('base URL (string)', async t => {
|
|
195
|
-
const
|
|
185
|
+
const source = await fixture('base-url')
|
|
186
|
+
const html = await Maizzle.applyBaseUrl(source, 'https://example.com/')
|
|
196
187
|
|
|
197
|
-
t.is(html,
|
|
188
|
+
t.is(html, await expected('base-url'))
|
|
198
189
|
})
|
|
199
190
|
|
|
200
191
|
test('base URL (object)', async t => {
|
|
201
|
-
const
|
|
192
|
+
const source = await fixture('base-url')
|
|
193
|
+
const html = await Maizzle.applyBaseUrl(source, {
|
|
202
194
|
url: 'https://example.com/',
|
|
203
195
|
allTags: true,
|
|
204
196
|
styleTag: true,
|
|
205
197
|
inlineCss: true
|
|
206
198
|
})
|
|
207
199
|
|
|
208
|
-
t.is(html,
|
|
200
|
+
t.is(html, await expected('base-url'))
|
|
209
201
|
})
|
|
210
202
|
|
|
211
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
|
|
212
208
|
// eslint-disable-next-line
|
|
213
209
|
const html = await Maizzle.prettify('<div><p>test</p></div>', {indent_inner_result: true})
|
|
214
|
-
const html2 = await Maizzle.prettify('<div><p>test</p></div>', true)
|
|
215
210
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
})
|
|
211
|
+
// No config
|
|
212
|
+
const html3 = await Maizzle.prettify('<div><p>test</p></div>')
|
|
219
213
|
|
|
220
|
-
|
|
221
|
-
const
|
|
214
|
+
// Empty object config
|
|
215
|
+
const html4 = await Maizzle.prettify('<div><p>test</p></div>', {})
|
|
222
216
|
|
|
223
|
-
t.is(html, '<div
|
|
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>')
|
|
224
221
|
})
|
|
225
222
|
|
|
226
223
|
test('minify', async t => {
|
|
@@ -282,14 +279,15 @@ test('six digit hex (disabled)', async t => {
|
|
|
282
279
|
t.is(html, '<td style="color: #ffc" bgcolor="#000"></td>')
|
|
283
280
|
})
|
|
284
281
|
|
|
285
|
-
test('
|
|
286
|
-
const
|
|
282
|
+
test('filters (default)', async t => {
|
|
283
|
+
const source = await fixture('filters')
|
|
284
|
+
const html = await Maizzle.withFilters(source)
|
|
287
285
|
|
|
288
|
-
t.is(html, '
|
|
286
|
+
t.is(html, await expected('filters'))
|
|
289
287
|
})
|
|
290
288
|
|
|
291
|
-
test('
|
|
292
|
-
const html = await Maizzle.
|
|
289
|
+
test('filters (tailwindcss)', async t => {
|
|
290
|
+
const html = await Maizzle.withFilters(
|
|
293
291
|
`<style tailwindcss>
|
|
294
292
|
div {
|
|
295
293
|
@apply hidden;
|
|
@@ -300,15 +298,20 @@ test('transform contents (tailwindcss)', async t => {
|
|
|
300
298
|
const expected = `<style>.inline { display: inline !important
|
|
301
299
|
} .table { display: table !important
|
|
302
300
|
} .contents { display: contents !important
|
|
303
|
-
} .
|
|
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
|
|
304
306
|
} div { display: none
|
|
305
|
-
}
|
|
307
|
+
}
|
|
308
|
+
</style>`
|
|
306
309
|
|
|
307
310
|
t.is(html, expected)
|
|
308
311
|
})
|
|
309
312
|
|
|
310
|
-
test('
|
|
311
|
-
const html = await Maizzle.
|
|
313
|
+
test('filters (postcss)', async t => {
|
|
314
|
+
const html = await Maizzle.withFilters(
|
|
312
315
|
`<style postcss>@import 'test/stubs/post.css';</style>`
|
|
313
316
|
)
|
|
314
317
|
|
|
@@ -477,3 +480,32 @@ test('remove inlined selectors (disabled)', async t => {
|
|
|
477
480
|
|
|
478
481
|
t.is(result, expected)
|
|
479
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
|
+
})
|
package/xo.config.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
space: true,
|
|
3
|
-
rules: {
|
|
4
|
-
semi: 0,
|
|
5
|
-
complexity: 0,
|
|
6
|
-
'max-params': 0,
|
|
7
|
-
'no-lonely-if': 0,
|
|
8
|
-
'unicorn/no-reduce': 0,
|
|
9
|
-
'import/extensions': 0,
|
|
10
|
-
'operator-linebreak': 0,
|
|
11
|
-
'max-nested-callbacks': 0,
|
|
12
|
-
'unicorn/filename-case': 0,
|
|
13
|
-
'unicorn/no-hex-escape': 0,
|
|
14
|
-
'unicorn/prefer-ternary': 0,
|
|
15
|
-
'unicorn/string-content': 0,
|
|
16
|
-
'unicorn/no-array-for-each': 0,
|
|
17
|
-
'unicorn/prefer-array-find': 0,
|
|
18
|
-
'promise/prefer-await-to-then': 0,
|
|
19
|
-
'unicorn/no-abusive-eslint-disable': 0,
|
|
20
|
-
quotes: ['error', 'single', {allowTemplateLiterals: true}]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
space: true,
|
|
3
|
+
rules: {
|
|
4
|
+
semi: 0,
|
|
5
|
+
complexity: 0,
|
|
6
|
+
'max-params': 0,
|
|
7
|
+
'no-lonely-if': 0,
|
|
8
|
+
'unicorn/no-reduce': 0,
|
|
9
|
+
'import/extensions': 0,
|
|
10
|
+
'operator-linebreak': 0,
|
|
11
|
+
'max-nested-callbacks': 0,
|
|
12
|
+
'unicorn/filename-case': 0,
|
|
13
|
+
'unicorn/no-hex-escape': 0,
|
|
14
|
+
'unicorn/prefer-ternary': 0,
|
|
15
|
+
'unicorn/string-content': 0,
|
|
16
|
+
'unicorn/no-array-for-each': 0,
|
|
17
|
+
'unicorn/prefer-array-find': 0,
|
|
18
|
+
'promise/prefer-await-to-then': 0,
|
|
19
|
+
'unicorn/no-abusive-eslint-disable': 0,
|
|
20
|
+
quotes: ['error', 'single', {allowTemplateLiterals: true}]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<a href="https://example.com">Test</a>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<a href="https://example.com">Test</a>
|