@newlogic-digital/core 1.0.0 → 1.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/index.js +96 -59
- package/package.json +1 -1
package/index.js
CHANGED
@@ -33,7 +33,74 @@ const stripIndent = (string) => {
|
|
33
33
|
return string.replace(regex, '')
|
34
34
|
}
|
35
35
|
|
36
|
+
const parsePrism = (type, input) => {
|
37
|
+
const Normalize = new NormalizeWhitespace({
|
38
|
+
'remove-trailing': true,
|
39
|
+
'remove-indent': true,
|
40
|
+
'left-trim': true,
|
41
|
+
'right-trim': true,
|
42
|
+
});
|
43
|
+
|
44
|
+
const wrap = (code, lang) => {
|
45
|
+
return `<pre class="language-${lang}"><code>${code}</code></pre>`
|
46
|
+
}
|
47
|
+
|
48
|
+
const highlight = (str, lang) => {
|
49
|
+
if (!lang) {
|
50
|
+
return wrap(str, 'text')
|
51
|
+
}
|
52
|
+
lang = lang.toLowerCase()
|
53
|
+
const rawLang = lang
|
54
|
+
if (lang === 'vue' || lang === 'html') {
|
55
|
+
lang = 'markup'
|
56
|
+
}
|
57
|
+
if (lang === 'md') {
|
58
|
+
lang = 'markdown'
|
59
|
+
}
|
60
|
+
if (lang === 'ts') {
|
61
|
+
lang = 'typescript'
|
62
|
+
}
|
63
|
+
if (lang === 'py') {
|
64
|
+
lang = 'python'
|
65
|
+
}
|
66
|
+
if (!Prism.languages[lang]) {
|
67
|
+
try {
|
68
|
+
loadLanguages([lang])
|
69
|
+
} catch (e) {
|
70
|
+
console.warn(`Syntax highlight for language "${lang}" is not supported.`)
|
71
|
+
}
|
72
|
+
}
|
73
|
+
if (Prism.languages[lang]) {
|
74
|
+
const code = Prism.highlight(Normalize.normalize(str), Prism.languages[lang], lang)
|
75
|
+
return wrap(code, rawLang)
|
76
|
+
}
|
77
|
+
return wrap(str, 'text')
|
78
|
+
}
|
79
|
+
|
80
|
+
return highlight(input, type);
|
81
|
+
}
|
82
|
+
|
83
|
+
const parseMinifyHtml = async (input, name) => {
|
84
|
+
const minify = await minifier.minify(input, {
|
85
|
+
collapseWhitespace: true,
|
86
|
+
collapseInlineTagWhitespace: false,
|
87
|
+
minifyCSS: true,
|
88
|
+
removeAttributeQuotes: true,
|
89
|
+
quoteCharacter: '\'',
|
90
|
+
minifyJS: true
|
91
|
+
})
|
92
|
+
|
93
|
+
if (name) {
|
94
|
+
return JSON.stringify({
|
95
|
+
[name]: minify
|
96
|
+
})
|
97
|
+
} else {
|
98
|
+
return JSON.stringify(minify)
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
36
102
|
const defaultConfig = {
|
103
|
+
format: 'twig',
|
37
104
|
posthtml: {},
|
38
105
|
juice: {},
|
39
106
|
tailwind: {},
|
@@ -121,26 +188,15 @@ const defaultConfig = {
|
|
121
188
|
const name = Reflect.apply(Twig.expression.parse, this, [token.stack, context])
|
122
189
|
const output = this.parse(token.output, context)
|
123
190
|
|
124
|
-
const minify = await minifier.minify(output, {
|
125
|
-
collapseWhitespace: true,
|
126
|
-
collapseInlineTagWhitespace: false,
|
127
|
-
minifyCSS: true,
|
128
|
-
removeAttributeQuotes: true,
|
129
|
-
quoteCharacter: '\'',
|
130
|
-
minifyJS: true
|
131
|
-
})
|
132
|
-
|
133
191
|
if (name === '_null') {
|
134
192
|
return {
|
135
193
|
chain,
|
136
|
-
output:
|
194
|
+
output: await parseMinifyHtml(output)
|
137
195
|
}
|
138
196
|
} else {
|
139
197
|
return {
|
140
198
|
chain,
|
141
|
-
output:
|
142
|
-
[name]: minify
|
143
|
-
})
|
199
|
+
output: await parseMinifyHtml(output, name)
|
144
200
|
}
|
145
201
|
}
|
146
202
|
}
|
@@ -179,52 +235,9 @@ const defaultConfig = {
|
|
179
235
|
type = type.replace(":mirror", "")
|
180
236
|
}
|
181
237
|
|
182
|
-
const Normalize = new NormalizeWhitespace({
|
183
|
-
'remove-trailing': true,
|
184
|
-
'remove-indent': true,
|
185
|
-
'left-trim': true,
|
186
|
-
'right-trim': true,
|
187
|
-
});
|
188
|
-
|
189
|
-
const wrap = (code, lang) => {
|
190
|
-
return `<pre class="language-${lang}"><code>${code}</code></pre>`
|
191
|
-
}
|
192
|
-
|
193
|
-
const highlight = (str, lang) => {
|
194
|
-
if (!lang) {
|
195
|
-
return wrap(str, 'text')
|
196
|
-
}
|
197
|
-
lang = lang.toLowerCase()
|
198
|
-
const rawLang = lang
|
199
|
-
if (lang === 'vue' || lang === 'html') {
|
200
|
-
lang = 'markup'
|
201
|
-
}
|
202
|
-
if (lang === 'md') {
|
203
|
-
lang = 'markdown'
|
204
|
-
}
|
205
|
-
if (lang === 'ts') {
|
206
|
-
lang = 'typescript'
|
207
|
-
}
|
208
|
-
if (lang === 'py') {
|
209
|
-
lang = 'python'
|
210
|
-
}
|
211
|
-
if (!Prism.languages[lang]) {
|
212
|
-
try {
|
213
|
-
loadLanguages([lang])
|
214
|
-
} catch (e) {
|
215
|
-
console.warn(`Syntax highlight for language "${lang}" is not supported.`)
|
216
|
-
}
|
217
|
-
}
|
218
|
-
if (Prism.languages[lang]) {
|
219
|
-
const code = Prism.highlight(Normalize.normalize(str), Prism.languages[lang], lang)
|
220
|
-
return wrap(code, rawLang)
|
221
|
-
}
|
222
|
-
return wrap(str, 'text')
|
223
|
-
}
|
224
|
-
|
225
238
|
return {
|
226
239
|
chain: chain,
|
227
|
-
output: `${mirror ? output : ""}${
|
240
|
+
output: `${mirror ? output : ""}${parsePrism(type, output)}`
|
228
241
|
};
|
229
242
|
}
|
230
243
|
});
|
@@ -238,7 +251,31 @@ const defaultConfig = {
|
|
238
251
|
]
|
239
252
|
},
|
240
253
|
latte: {
|
241
|
-
isStringFilter: (filename) => dirname(filename).endsWith('emails')
|
254
|
+
isStringFilter: (filename) => dirname(filename).endsWith('emails'),
|
255
|
+
globals: {
|
256
|
+
srcPath: resolve(process.cwd(), 'src'),
|
257
|
+
templatesPath: resolve(process.cwd(), 'src/templates')
|
258
|
+
},
|
259
|
+
functions: {
|
260
|
+
pages: () => {
|
261
|
+
return fs.readdirSync(resolve(process.cwd(), 'src/views')).filter(file => fs.statSync(resolve(process.cwd(), 'src/views/' + file)).isFile())
|
262
|
+
},
|
263
|
+
// code: (input, type = '') => {
|
264
|
+
// let mirror = false;
|
265
|
+
//
|
266
|
+
// if (type.includes(":mirror")) {
|
267
|
+
// mirror = true;
|
268
|
+
// type = type.replace(":mirror", "")
|
269
|
+
// }
|
270
|
+
//
|
271
|
+
// return `${mirror ? input : ""}${parsePrism(type, input)}`
|
272
|
+
// }
|
273
|
+
},
|
274
|
+
filters: {
|
275
|
+
json: async (input, name) => {
|
276
|
+
return await parseMinifyHtml(input, name)
|
277
|
+
}
|
278
|
+
}
|
242
279
|
}
|
243
280
|
}
|
244
281
|
|
@@ -254,7 +291,7 @@ const integration = (userConfig = {}) => {
|
|
254
291
|
reload: file => (file.endsWith('.tpl') || file.endsWith('.latte')) && !file.includes('temp/')
|
255
292
|
},
|
256
293
|
templates: {
|
257
|
-
format:
|
294
|
+
format: userConfig.format
|
258
295
|
},
|
259
296
|
imports: {
|
260
297
|
paths: ['./src/styles/**', './src/scripts/**', '!./src/styles/Utils/**']
|
package/package.json
CHANGED