@maizzle/framework 4.6.5 → 4.7.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/README.md +1 -1
- package/package.json +2 -3
- package/src/index.d.ts +4 -4
- package/src/transformers/prettify.js +23 -10
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maizzle/framework",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -71,14 +71,13 @@
|
|
|
71
71
|
"posthtml-postcss-merge-longhand": "^2.0.1",
|
|
72
72
|
"posthtml-safe-class-names": "^3.0.0",
|
|
73
73
|
"posthtml-url-parameters": "^2.0.0",
|
|
74
|
-
"
|
|
74
|
+
"prettier": "^3.1.1",
|
|
75
75
|
"query-string": "^7.1.3",
|
|
76
76
|
"string-remove-widows": "^2.1.0",
|
|
77
77
|
"string-strip-html": "^8.2.0",
|
|
78
78
|
"tailwindcss": "^3.2.7"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@types/js-beautify": "^1.14.0",
|
|
82
81
|
"@types/markdown-it": "^13.0.0",
|
|
83
82
|
"ava": "^5.2.0",
|
|
84
83
|
"c8": "^9.0.0",
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {StringifyOptions} from 'query-string';
|
|
2
|
-
import type {
|
|
2
|
+
import type {Config as PrettierOptions} from 'prettier';
|
|
3
3
|
import type {Options as MarkdownItOptions} from 'markdown-it';
|
|
4
4
|
import type {Opts as PlaintextOptions} from 'string-strip-html';
|
|
5
5
|
|
|
@@ -1773,7 +1773,7 @@ declare namespace MaizzleFramework {
|
|
|
1773
1773
|
}
|
|
1774
1774
|
```
|
|
1775
1775
|
*/
|
|
1776
|
-
prettify?: boolean |
|
|
1776
|
+
prettify?: boolean | PrettierOptions;
|
|
1777
1777
|
|
|
1778
1778
|
/**
|
|
1779
1779
|
Minify the compiled HTML email code.
|
|
@@ -2041,9 +2041,9 @@ declare namespace MaizzleFramework {
|
|
|
2041
2041
|
/**
|
|
2042
2042
|
Pretty print HTML code so that it's nicely indented and more human-readable.
|
|
2043
2043
|
@param {string} html The HTML string to prettify.
|
|
2044
|
-
@param {
|
|
2044
|
+
@param {PrettierOptions} [options] Options to pass to the prettifier.
|
|
2045
2045
|
*/
|
|
2046
|
-
function prettify(html: string, options?:
|
|
2046
|
+
function prettify(html: string, options?: PrettierOptions): string;
|
|
2047
2047
|
|
|
2048
2048
|
/**
|
|
2049
2049
|
Prepend a string to sources and hrefs in an HTML string.
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
const pretty = require('pretty')
|
|
1
|
+
const {format} = require('prettier')
|
|
3
2
|
const {get, merge, isEmpty, isObject} = require('lodash')
|
|
4
3
|
|
|
5
4
|
module.exports = async (html, config = {}, direct = false) => {
|
|
5
|
+
config = direct ? config : get(config, 'prettify')
|
|
6
|
+
|
|
6
7
|
const defaultConfig = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
parser: 'html',
|
|
9
|
+
printWidth: 500,
|
|
10
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
11
|
+
xmlMode: get(config, 'posthtml.options.xmlMode', false)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
config = direct ? config : get(config, 'prettify')
|
|
14
|
-
|
|
15
14
|
// Don't prettify if not explicitly enabled in config
|
|
16
15
|
if (!config || (isObject(config) && isEmpty(config))) {
|
|
17
16
|
return html
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
if (typeof config === 'boolean' && config) {
|
|
21
|
-
return
|
|
20
|
+
return format(html, defaultConfig).then(html => reFormat(html, defaultConfig))
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
config = merge(defaultConfig, config)
|
|
25
24
|
|
|
26
|
-
return
|
|
25
|
+
return format(html, config).then(html => reFormat(html, config))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const reFormat = (html, config) => {
|
|
29
|
+
if (/<!doctype html>/i.test(html) && !config.xmlMode) {
|
|
30
|
+
html = html.replace(/<(.+?)(\s\/)>/g, '<$1>')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return html
|
|
34
|
+
.replace(/,\s*/g, ', ')
|
|
35
|
+
.replace(/(\s+style="\s+)([\s\S]*?)(\s+")/g, (match, p1, p2, p3) => {
|
|
36
|
+
return p1.replace(/\n\s+?(style)/g, ' $1').trimEnd()
|
|
37
|
+
+ p2.replace(/\s+/g, ' ').trim()
|
|
38
|
+
+ p3.trim()
|
|
39
|
+
})
|
|
27
40
|
}
|