@maizzle/framework 4.6.4 → 4.7.0

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 CHANGED
@@ -7,7 +7,7 @@
7
7
  </picture>
8
8
  </a>
9
9
  </p>
10
- <p>Quickly build HTML emails with utility-first CSS</p>
10
+ <p>Quickly build HTML emails with Tailwind CSS</p>
11
11
  <div>
12
12
 
13
13
  [![Version][npm-version-shield]][npm]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "4.6.4",
3
+ "version": "4.7.0",
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",
@@ -61,7 +61,7 @@
61
61
  "posthtml-attrs-parser": "^0.1.1",
62
62
  "posthtml-base-url": "^2.0.0",
63
63
  "posthtml-component": "^1.1.0",
64
- "posthtml-content": "^0.1.0",
64
+ "posthtml-content": "^1.0.2",
65
65
  "posthtml-extend": "^0.6.0",
66
66
  "posthtml-extra-attributes": "^2.0.0",
67
67
  "posthtml-fetch": "^3.0.0",
@@ -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
- "pretty": "^2.0.0",
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 {CoreBeautifyOptions} from 'js-beautify';
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 | CoreBeautifyOptions;
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 {CoreBeautifyOptions} [options] Options to pass to the prettifier.
2044
+ @param {PrettierOptions} [options] Options to pass to the prettifier.
2045
2045
  */
2046
- function prettify(html: string, options?: CoreBeautifyOptions): string;
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,39 @@
1
- /* eslint-disable camelcase */
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
- space_around_combinator: true, // Preserve space around CSS selector combinators
8
- newline_between_rules: false, // Remove empty lines between CSS rules
9
- indent_inner_html: false, // Helps reduce file size
10
- extra_liners: [] // Don't add extra new line before any tag
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 pretty(html, defaultConfig)
20
+ return format(html, defaultConfig).then(html => reFormat(html, defaultConfig))
22
21
  }
23
22
 
24
23
  config = merge(defaultConfig, config)
25
24
 
26
- return pretty(html, config)
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
+ const formattedStyle = p2.replace(/\s+/g, ' ').trim()
37
+ return p1.trim() + formattedStyle + p3.trim()
38
+ })
27
39
  }