@maizzle/framework 5.0.0-beta.26 → 5.0.0-beta.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "5.0.0-beta.26",
3
+ "version": "5.0.0-beta.28",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -67,8 +67,8 @@
67
67
  "morphdom": "^2.7.4",
68
68
  "ora": "^8.1.0",
69
69
  "pathe": "^1.1.2",
70
- "postcss": "^8.4.47",
71
- "postcss-custom-properties": "^14.0.1",
70
+ "postcss": "^8.4.49",
71
+ "postcss-custom-properties": "^14.0.4",
72
72
  "postcss-import": "^16.1.0",
73
73
  "postcss-safe-parser": "^7.0.0",
74
74
  "posthtml": "^0.16.6",
@@ -87,10 +87,10 @@
87
87
  "posthtml-render": "^3.0.0",
88
88
  "posthtml-safe-class-names": "^4.1.0",
89
89
  "posthtml-url-parameters": "^3.1.0",
90
+ "posthtml-widows": "^1.0.0",
90
91
  "pretty": "^2.0.0",
91
- "string-remove-widows": "^4.0.22",
92
92
  "string-strip-html": "^13.4.8",
93
- "tailwindcss": "^3.4.13",
93
+ "tailwindcss": "^3.4.15",
94
94
  "ws": "^8.18.0"
95
95
  },
96
96
  "devDependencies": {
@@ -3,8 +3,8 @@ import posthtml from 'posthtml'
3
3
  import get from 'lodash-es/get.js'
4
4
  import { defu as merge } from 'defu'
5
5
  import { stripHtml } from 'string-strip-html'
6
- import defaultConfig from '../posthtml/defaultConfig.js'
7
6
  import { writeFile, lstat, mkdir } from 'node:fs/promises'
7
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
8
8
 
9
9
  /**
10
10
  * Removes HTML tags from a given HTML string based on
@@ -46,7 +46,7 @@ const removeTags = ({ tag = 'not-plaintext', html = '', config = {} }) => {
46
46
  return tree.walk(process)
47
47
  }
48
48
 
49
- const posthtmlOptions = merge(defaultConfig, config)
49
+ const posthtmlOptions = merge(config, getPosthtmlOptions())
50
50
 
51
51
  return posthtml([posthtmlPlugin()]).process(html, { ...posthtmlOptions }).then(res => res.html)
52
52
  }
@@ -95,7 +95,7 @@ export async function handlePlaintextTags(html = '', config = {}) {
95
95
  return tree.walk(process)
96
96
  }
97
97
 
98
- const posthtmlOptions = merge(defaultConfig, config)
98
+ const posthtmlOptions = merge(config, getPosthtmlOptions())
99
99
 
100
100
  return posthtml([posthtmlPlugin()]).process(html, { ...posthtmlOptions }).then(res => res.html)
101
101
  }
@@ -4,7 +4,7 @@ import { cwd } from 'node:process'
4
4
  import { defu as merge } from 'defu'
5
5
  import expressions from 'posthtml-expressions'
6
6
  import { parseFrontMatter } from '../utils/node.js'
7
- import defaultConfig from '../posthtml/defaultConfig.js'
7
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
8
8
  import { process as compilePostHTML } from '../posthtml/index.js'
9
9
  import { run as useTransformers } from '../transformers/index.js'
10
10
 
@@ -41,7 +41,7 @@ export async function render(html = '', config = {}) {
41
41
  })
42
42
  ]
43
43
  )
44
- .process(matter, defaultConfig)
44
+ .process(matter, getPosthtmlOptions())
45
45
  .then(({ html }) => parseFrontMatter(`---${html}\n---`))
46
46
 
47
47
  const templateConfig = merge(matterData, config)
@@ -1,8 +1,8 @@
1
1
  export default {
2
2
  root: './',
3
- folders: ['src/components', 'src/layouts', 'src/templates'],
4
- fileExtension: 'html',
5
3
  tag: 'component',
4
+ fileExtension: 'html',
5
+ folders: ['src/components', 'src/layouts', 'src/templates'],
6
6
  expressions: {
7
7
  loopTags: ['each', 'for'],
8
8
  missingLocal: '{local}',
@@ -1,4 +1,14 @@
1
- export default {
2
- recognizeNoValueAttribute: true,
3
- recognizeSelfClosing: true
1
+ import { defu as merge } from 'defu'
2
+
3
+ export function getPosthtmlOptions(userConfigOptions = {}) {
4
+ return merge(
5
+ userConfigOptions,
6
+ {
7
+ recognizeNoValueAttribute: true,
8
+ recognizeSelfClosing: true,
9
+ directives: [
10
+ { name: '?php', start: '<', end: '>' },
11
+ ],
12
+ }
13
+ )
4
14
  }
@@ -7,9 +7,9 @@ import posthtmlFetch from 'posthtml-fetch'
7
7
  import envTags from './plugins/envTags.js'
8
8
  import components from 'posthtml-component'
9
9
  import posthtmlPostcss from 'posthtml-postcss'
10
- import defaultPosthtmlConfig from './defaultConfig.js'
11
10
  import expandLinkTag from './plugins/expandLinkTag.js'
12
11
  import envAttributes from './plugins/envAttributes.js'
12
+ import { getPosthtmlOptions } from './defaultConfig.js'
13
13
 
14
14
  // PostCSS
15
15
  import tailwindcss from 'tailwindcss'
@@ -36,7 +36,7 @@ export async function process(html = '', config = {}) {
36
36
  )
37
37
  )
38
38
 
39
- const posthtmlOptions = merge(get(config, 'posthtml.options', {}), defaultPosthtmlConfig)
39
+ const posthtmlOptions = getPosthtmlOptions(get(config, 'posthtml.options', {}))
40
40
 
41
41
  const componentsUserOptions = get(config, 'components', {})
42
42
 
@@ -1,6 +1,5 @@
1
1
  import posthtml from 'posthtml'
2
2
  import { defu as merge } from 'defu'
3
- import posthtmlConfig from '../posthtml/defaultConfig.js'
4
3
  import addAttributesPlugin from 'posthtml-extra-attributes'
5
4
 
6
5
  export default function posthtmlPlugin(attributes = {}) {
@@ -25,6 +24,6 @@ export async function addAttributes(html = '', attributes = {}, posthtmlOptions
25
24
  return posthtml([
26
25
  posthtmlPlugin(attributes)
27
26
  ])
28
- .process(html, merge(posthtmlOptions, posthtmlConfig))
27
+ .process(html, posthtmlOptions)
29
28
  .then(result => result.html)
30
29
  }
@@ -1,11 +1,9 @@
1
1
  import posthtml from 'posthtml'
2
2
  import get from 'lodash-es/get.js'
3
- import { defu as merge } from 'defu'
4
3
  import keys from 'lodash-es/keys.js'
5
4
  import forEach from 'lodash-es/forEach.js'
6
5
  import parseAttrs from 'posthtml-attrs-parser'
7
6
  import intersection from 'lodash-es/intersection.js'
8
- import posthtmlConfig from '../posthtml/defaultConfig.js'
9
7
 
10
8
  const posthtmlPlugin = (attributes = []) => tree => {
11
9
  if (!Array.isArray(attributes)) {
@@ -87,6 +85,6 @@ export async function attributeToStyle(html = '', attributes = [], posthtmlOptio
87
85
  return posthtml([
88
86
  posthtmlPlugin(attributes)
89
87
  ])
90
- .process(html, merge(posthtmlOptions, posthtmlConfig))
88
+ .process(html, posthtmlOptions)
91
89
  .then(result => result.html)
92
90
  }
@@ -1,13 +1,14 @@
1
1
  import posthtml from 'posthtml'
2
2
  import isUrl from 'is-url-superb'
3
3
  import get from 'lodash-es/get.js'
4
- import { defu as merge } from 'defu'
5
4
  import baseUrl from 'posthtml-base-url'
6
5
  import { render } from 'posthtml-render'
7
6
  import isEmpty from 'lodash-es/isEmpty.js'
8
7
  import isObject from 'lodash-es/isObject.js'
9
8
  import { parser as parse } from 'posthtml-parser'
10
- import posthtmlConfig from '../posthtml/defaultConfig.js'
9
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
10
+
11
+ const posthtmlOptions = getPosthtmlOptions()
11
12
 
12
13
  const posthtmlPlugin = url => tree => {
13
14
  // Handle `baseURL` as a string
@@ -19,7 +20,7 @@ const posthtmlPlugin = url => tree => {
19
20
  allTags: true,
20
21
  styleTag: true,
21
22
  inlineCss: true
22
- })(parse(html, posthtmlConfig))
23
+ })(parse(html, posthtmlOptions))
23
24
  }
24
25
 
25
26
  // Handle `baseURL` as an object
@@ -31,7 +32,6 @@ const posthtmlPlugin = url => tree => {
31
32
  allTags,
32
33
  tags,
33
34
  url: baseURL,
34
- ...posthtmlOptions
35
35
  } = url
36
36
 
37
37
  return baseUrl({
@@ -40,7 +40,7 @@ const posthtmlPlugin = url => tree => {
40
40
  allTags,
41
41
  tags,
42
42
  url: baseURL,
43
- })(parse(html, merge(posthtmlConfig, posthtmlOptions)))
43
+ })(parse(html, posthtmlOptions))
44
44
  }
45
45
 
46
46
  return tree
@@ -52,7 +52,7 @@ export async function addBaseUrl(html = '', options = {}, posthtmlOptions = {})
52
52
  return posthtml([
53
53
  posthtmlPlugin(options)
54
54
  ])
55
- .process(html, merge(posthtmlOptions, posthtmlConfig))
55
+ .process(html, getPosthtmlOptions())
56
56
  .then(result => result.html)
57
57
  }
58
58
 
@@ -4,7 +4,7 @@ import { defu as merge } from 'defu'
4
4
  import { render } from 'posthtml-render'
5
5
  import { comb as emailComb } from 'email-comb'
6
6
  import { parser as parse } from 'posthtml-parser'
7
- import posthtmlConfig from '../posthtml/defaultConfig.js'
7
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
8
8
 
9
9
  const posthtmlPlugin = options => tree => {
10
10
  const defaultSafelist = [
@@ -35,6 +35,7 @@ const posthtmlPlugin = options => tree => {
35
35
 
36
36
  options = merge(options, defaultOptions)
37
37
 
38
+ const posthtmlConfig = getPosthtmlOptions()
38
39
  const { result: html } = emailComb(render(tree), options)
39
40
 
40
41
  return parse(html, posthtmlConfig)
@@ -42,10 +43,10 @@ const posthtmlPlugin = options => tree => {
42
43
 
43
44
  export default posthtmlPlugin
44
45
 
45
- export async function comb(html = '', options = {}, posthtmlOptions = {}) {
46
+ export async function comb(html = '', pluginOptions = {}, posthtmlOptions = {}) {
46
47
  return posthtml([
47
- posthtmlPlugin(options)
48
+ posthtmlPlugin(pluginOptions)
48
49
  ])
49
- .process(html, merge(posthtmlOptions, posthtmlConfig))
50
+ .process(html, posthtmlOptions)
50
51
  .then(result => result.html)
51
52
  }
@@ -1,7 +1,6 @@
1
1
  import posthtml from 'posthtml'
2
2
  import { defu as merge } from 'defu'
3
3
  import posthtmlContent from 'posthtml-content'
4
- import posthtmlConfig from '../../posthtml/defaultConfig.js'
5
4
  import { filters as defaultFilters } from './defaultFilters.js'
6
5
 
7
6
  export default function posthtmlPlugin(filters = {}) {
@@ -14,6 +13,6 @@ export async function filters(html = '', filters = {}, posthtmlOptions = {}) {
14
13
  return posthtml([
15
14
  posthtmlPlugin(filters)
16
15
  ])
17
- .process(html, merge(posthtmlOptions, posthtmlConfig))
16
+ .process(html, posthtmlOptions)
18
17
  .then(result => result.html)
19
18
  }
@@ -22,7 +22,7 @@ import replaceStrings from './replaceStrings.js'
22
22
  import attributeToStyle from './attributeToStyle.js'
23
23
  import removeAttributes from './removeAttributes.js'
24
24
 
25
- import defaultPosthtmlConfig from '../posthtml/defaultConfig.js'
25
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
26
26
 
27
27
  /**
28
28
  * Use Maizzle Transformers on an HTML string.
@@ -37,10 +37,7 @@ import defaultPosthtmlConfig from '../posthtml/defaultConfig.js'
37
37
  export async function run(html = '', config = {}) {
38
38
  const posthtmlPlugins = []
39
39
 
40
- const posthtmlConfig = merge(
41
- get(config, 'posthtml.options', {}),
42
- defaultPosthtmlConfig
43
- )
40
+ const posthtmlConfig = getPosthtmlOptions(get(config, 'posthtml.options', {}))
44
41
 
45
42
  /**
46
43
  * 1. Core transformers
@@ -221,35 +218,35 @@ export async function run(html = '', config = {}) {
221
218
  posthtmlPlugins.push(templateTag())
222
219
 
223
220
  /**
224
- * 17. Prettify
221
+ * 17. Replace strings
225
222
  *
226
- * Pretty-print HTML using js-beautify.
223
+ * Replace strings through regular expressions.
227
224
  */
228
- if (get(config, 'prettify')) {
225
+ if (get(config, 'replaceStrings')) {
229
226
  posthtmlPlugins.push(
230
- prettify(get(config, 'prettify', {}))
227
+ replaceStrings(get(config, 'replaceStrings', {}))
231
228
  )
232
229
  }
233
230
 
234
231
  /**
235
- * 18. Minify
232
+ * 18. Prettify
236
233
  *
237
- * Minify HTML using html-crush.
234
+ * Pretty-print HTML using js-beautify.
238
235
  */
239
- if (get(config, 'minify')) {
236
+ if (get(config, 'prettify')) {
240
237
  posthtmlPlugins.push(
241
- minify(get(config, 'minify', {}))
238
+ prettify(get(config, 'prettify', {}))
242
239
  )
243
240
  }
244
241
 
245
242
  /**
246
- * 19. Replace strings
243
+ * 19. Minify
247
244
  *
248
- * Replace strings through regular expressions.
245
+ * Minify HTML using html-crush.
249
246
  */
250
- if (get(config, 'replaceStrings')) {
247
+ if (get(config, 'minify')) {
251
248
  posthtmlPlugins.push(
252
- replaceStrings(get(config, 'replaceStrings', {}))
249
+ minify(get(config, 'minify', {}))
253
250
  )
254
251
  }
255
252
 
@@ -12,10 +12,10 @@ import isObject from 'lodash-es/isObject.js'
12
12
  import { parser as parse } from 'posthtml-parser'
13
13
  import { parseCSSRule } from '../utils/string.js'
14
14
  import { useAttributeSizes } from './useAttributeSizes.js'
15
- import defaultPostHTMLConfig from '../posthtml/defaultConfig.js'
15
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
16
16
 
17
17
  const posthtmlPlugin = (options = {}) => tree => {
18
- return inline(render(tree), options).then(html => parse(html, defaultPostHTMLConfig))
18
+ return inline(render(tree), options).then(html => parse(html, getPosthtmlOptions()))
19
19
  }
20
20
 
21
21
  export default posthtmlPlugin
@@ -150,7 +150,7 @@ export async function inline(html = '', options = {}) {
150
150
  rule.walkDecls(decl => {
151
151
  // Resolve calc() values to static values
152
152
  if (options.resolveCalc) {
153
- decl.value = decl.value.includes('calc(') ? calc(decl.value, {precision: 2}) : decl.value
153
+ decl.value = decl.value.includes('calc(') ? calc(decl.value, { precision: 2 }) : decl.value
154
154
  }
155
155
 
156
156
  declarations.add(decl)
@@ -164,10 +164,10 @@ export async function inline(html = '', options = {}) {
164
164
  */
165
165
  if (options.resolveCSSVariables) {
166
166
  Array.from(declarations)
167
- /**
168
- * Consider only declarations with a value that includes any of the other declarations' property
169
- * So a decl like color(var(--text-color)) will be removed if there's a decl with a property of --text-color
170
- * */
167
+ /**
168
+ * Consider only declarations with a value that includes any of the other declarations' property
169
+ * So a decl like color(var(--text-color)) will be removed if there's a decl with a property of --text-color
170
+ * */
171
171
  .filter(decl =>
172
172
  Array.from(declarations).some(otherDecl => decl.value.includes(otherDecl.prop))
173
173
  || decl.prop.startsWith('--')
@@ -216,7 +216,7 @@ export async function inline(html = '', options = {}) {
216
216
  let { property, value } = parseCSSRule(i)
217
217
 
218
218
  if (value && options.resolveCalc) {
219
- value = value.includes('calc') ? calc(value, {precision: 2}) : value
219
+ value = value.includes('calc') ? calc(value, { precision: 2 }) : value
220
220
  }
221
221
 
222
222
  if (value && options.preferUnitlessValues) {
@@ -1,7 +1,5 @@
1
1
  import posthtml from 'posthtml'
2
- import { defu as merge } from 'defu'
3
2
  import md from 'posthtml-markdownit'
4
- import posthtmlConfig from '../posthtml/defaultConfig.js'
5
3
 
6
4
  export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
7
5
  /**
@@ -23,6 +21,6 @@ export async function markdown(input = '', options = {}, posthtmlOptions = {}) {
23
21
  return posthtml([
24
22
  md(options)
25
23
  ])
26
- .process(input, merge(posthtmlOptions, posthtmlConfig))
24
+ .process(input, posthtmlOptions)
27
25
  .then(result => result.html)
28
26
  }
@@ -3,17 +3,17 @@ import { crush } from 'html-crush'
3
3
  import { defu as merge } from 'defu'
4
4
  import { render } from 'posthtml-render'
5
5
  import { parser as parse } from 'posthtml-parser'
6
- import posthtmlConfig from '../posthtml/defaultConfig.js'
7
- import defaultPostHTMLConfig from '../posthtml/defaultConfig.js'
6
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
8
7
 
9
8
  const posthtmlPlugin = (options = {}) => tree => {
10
9
  options = merge(options, {
11
10
  removeLineBreaks: true,
12
11
  })
13
12
 
13
+ const posthtmlConfig = getPosthtmlOptions()
14
14
  const { result: html } = crush(render(tree), options)
15
15
 
16
- return parse(html, defaultPostHTMLConfig)
16
+ return parse(html, posthtmlConfig)
17
17
  }
18
18
 
19
19
  export default posthtmlPlugin
@@ -22,6 +22,6 @@ export async function minify(html = '', options = {}, posthtmlOptions = {}) {
22
22
  return posthtml([
23
23
  posthtmlPlugin(options)
24
24
  ])
25
- .process(html, merge(posthtmlOptions, posthtmlConfig))
25
+ .process(html, posthtmlOptions)
26
26
  .then(result => result.html)
27
27
  }
@@ -1,7 +1,5 @@
1
1
  import posthtml from 'posthtml'
2
- import { defu as merge } from 'defu'
3
2
  import posthtmlMso from 'posthtml-mso'
4
- import posthtmlConfig from '../posthtml/defaultConfig.js'
5
3
 
6
4
  export default function posthtmlPlugin(options = {}) {
7
5
  return posthtmlMso(options)
@@ -11,6 +9,6 @@ export async function useMso(html = '', options = {}, posthtmlOptions = {}) {
11
9
  return posthtml([
12
10
  posthtmlPlugin(options)
13
11
  ])
14
- .process(html, merge(posthtmlOptions, posthtmlConfig))
12
+ .process(html, posthtmlOptions)
15
13
  .then(result => result.html)
16
14
  }
@@ -3,7 +3,7 @@ import posthtml from 'posthtml'
3
3
  import { defu as merge } from 'defu'
4
4
  import { render } from 'posthtml-render'
5
5
  import { parser as parse } from 'posthtml-parser'
6
- import posthtmlConfig from '../posthtml/defaultConfig.js'
6
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
7
7
 
8
8
  const posthtmlPlugin = (options = {}) => tree => {
9
9
  const defaultConfig = {
@@ -15,7 +15,7 @@ const posthtmlPlugin = (options = {}) => tree => {
15
15
 
16
16
  const config = merge(options, defaultConfig)
17
17
 
18
- return parse(pretty(render(tree), config), posthtmlConfig)
18
+ return parse(pretty(render(tree), config), getPosthtmlOptions())
19
19
  }
20
20
 
21
21
  export default posthtmlPlugin
@@ -24,6 +24,6 @@ export async function prettify(html = '', options = {}, posthtmlOptions = {}) {
24
24
  return posthtml([
25
25
  posthtmlPlugin(options)
26
26
  ])
27
- .process(html, merge(posthtmlOptions, posthtmlConfig))
27
+ .process(html, posthtmlOptions)
28
28
  .then(result => result.html)
29
29
  }
@@ -1,87 +1,37 @@
1
1
  import posthtml from 'posthtml'
2
+ import posthtmlWidows from 'posthtml-widows'
2
3
  import { defu as merge } from 'defu'
3
- import { removeWidows } from 'string-remove-widows'
4
- import posthtmlConfig from '../posthtml/defaultConfig.js'
5
4
 
6
- const posthtmlPlugin = (options = {}) => tree => {
5
+ export default function posthtmlPlugin(options = {}) {
7
6
  options = merge(options, {
8
- minWordCount: 3,
9
- attrName: 'prevent-widows'
7
+ minWords: 3
10
8
  })
11
9
 
12
- // Ignore defaults
10
+ // Custom ignores
13
11
  const mappings = [
14
- // Jinja-like
15
- {
16
- heads: '{{',
17
- tails: '}}'
18
- },
19
- {
20
- heads: ['{% if', '{%- if'],
21
- tails: ['{% endif', '{%- endif']
22
- },
23
- {
24
- heads: ['{% for', '{%- for'],
25
- tails: ['{% endfor', '{%- endfor']
26
- },
27
- {
28
- heads: ['{%', '{%-'],
29
- tails: ['%}', '-%}']
30
- },
31
- {
32
- heads: '{#',
33
- tails: '#}'
34
- },
35
- // ASP/Hexo-like
36
- {
37
- heads: ['<%', '<%=', '<%-'],
38
- tails: ['%>', '=%>', '-%>']
39
- },
40
12
  // MSO comments
41
13
  {
42
- heads: '<!--[',
43
- tails: ']>'
14
+ start: '<!--[',
15
+ end: ']>'
44
16
  },
45
17
  // <![endif]-->
46
18
  {
47
- heads: '<![',
48
- tails: ']--><'
19
+ start: '<![',
20
+ end: ']--><'
49
21
  }
50
22
  ]
51
23
 
52
24
  if (Array.isArray(options.ignore)) {
53
- options.ignore.forEach(pair => mappings.push(pair))
54
- }
55
-
56
- if (typeof options.ignore !== 'string') {
57
- options.ignore = mappings
58
- }
59
-
60
- const process = node => {
61
- if (node.attrs && Object.keys(node.attrs).includes(options.attrName)) {
62
- const widowsRemovedString = removeWidows(tree.render(node.content), options).res
63
- node.content = tree.render(tree.parser(widowsRemovedString))
64
- delete node.attrs[options.attrName]
65
- }
66
-
67
- return node
25
+ options.ignore = options.ignore.concat(mappings)
68
26
  }
69
27
 
70
- return tree.walk(process)
28
+ return posthtmlWidows(options)
71
29
  }
72
30
 
73
- export default posthtmlPlugin
74
-
75
31
  export async function preventWidows(html = '', options = {}, posthtmlOptions = {}) {
76
- // Apply only to elements that contain the `prevent-widows` attribute
77
- if (options.withAttributes) {
78
- return posthtml([
79
- posthtmlPlugin(options)
80
- ])
81
- .process(html, merge(posthtmlOptions, posthtmlConfig))
82
- .then(result => result.html)
83
- }
84
-
85
- // Apply to all elements
86
- return removeWidows(html, options).res
32
+ return posthtml([
33
+ posthtmlPlugin(options)
34
+ ])
35
+ .process(html, posthtmlOptions)
36
+ .then(result => result.html)
87
37
  }
@@ -1,7 +1,6 @@
1
1
  import posthtml from 'posthtml'
2
2
  import get from 'lodash-es/get.js'
3
- import { defu as merge } from 'defu'
4
- import posthtmlConfig from '../posthtml/defaultConfig.js'
3
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
5
4
 
6
5
  /**
7
6
  * Remove empty attributes with PostHTML
@@ -49,8 +48,8 @@ export default posthtmlPlugin
49
48
 
50
49
  export async function removeAttributes(html = '', attributes = [], posthtmlOptions = {}) {
51
50
  return posthtml([
52
- posthtmlPlugin(attributes, merge(posthtmlOptions, posthtmlConfig))
51
+ posthtmlPlugin(attributes, getPosthtmlOptions(posthtmlOptions))
53
52
  ])
54
- .process(html, merge(posthtmlOptions, posthtmlConfig))
53
+ .process(html, getPosthtmlOptions())
55
54
  .then(result => result.html)
56
55
  }
@@ -1,10 +1,8 @@
1
1
  import posthtml from 'posthtml'
2
- import { defu as merge } from 'defu'
3
2
  import { render } from 'posthtml-render'
4
3
  import isEmpty from 'lodash-es/isEmpty.js'
5
4
  import { parser as parse } from 'posthtml-parser'
6
- import posthtmlConfig from '../posthtml/defaultConfig.js'
7
- import defaultPostHTMLConfig from '../posthtml/defaultConfig.js'
5
+ import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
8
6
 
9
7
  const posthtmlPlugin = (replacements = {}) => tree => {
10
8
  if (!isEmpty(replacements)) {
@@ -21,7 +19,7 @@ const posthtmlPlugin = (replacements = {}) => tree => {
21
19
 
22
20
  return matched
23
21
  }),
24
- defaultPostHTMLConfig
22
+ getPosthtmlOptions()
25
23
  )
26
24
  }
27
25
 
@@ -34,6 +32,6 @@ export async function replaceStrings(html = '', replacements = {}, posthtmlOptio
34
32
  return posthtml([
35
33
  posthtmlPlugin(replacements)
36
34
  ])
37
- .process(html, merge(posthtmlOptions, posthtmlConfig))
35
+ .process(html, posthtmlOptions)
38
36
  .then(result => result.html)
39
37
  }
@@ -1,6 +1,5 @@
1
1
  import posthtml from 'posthtml'
2
2
  import { defu as merge } from 'defu'
3
- import posthtmlConfig from '../posthtml/defaultConfig.js'
4
3
  import posthtmlSafeClassNames from 'posthtml-safe-class-names'
5
4
 
6
5
  export default function posthtmlPlugin(options = {}) {
@@ -24,6 +23,6 @@ export async function safeClassNames(html = '', options = {}, posthtmlOptions =
24
23
  return posthtml([
25
24
  posthtmlPlugin(options)
26
25
  ])
27
- .process(html, merge(posthtmlOptions, posthtmlConfig))
26
+ .process(html, posthtmlOptions)
28
27
  .then(result => result.html)
29
28
  }
@@ -1,6 +1,4 @@
1
1
  import posthtml from 'posthtml'
2
- import { defu as merge } from 'defu'
3
- import posthtmlConfig from '../posthtml/defaultConfig.js'
4
2
  import posthtmlMergeLonghand from 'posthtml-postcss-merge-longhand'
5
3
 
6
4
  export default function posthtmlPlugin(options = {}) {
@@ -17,6 +15,6 @@ export async function shorthandCSS(html = '', options = {}, posthtmlOptions = {}
17
15
  return posthtml([
18
16
  posthtmlPlugin(options)
19
17
  ])
20
- .process(html, merge(posthtmlOptions, posthtmlConfig))
18
+ .process(html, posthtmlOptions)
21
19
  .then(result => result.html)
22
20
  }
@@ -1,7 +1,5 @@
1
1
  import posthtml from 'posthtml'
2
- import { defu as merge } from 'defu'
3
2
  import { conv } from 'color-shorthand-hex-to-six-digit'
4
- import posthtmlConfig from '../posthtml/defaultConfig.js'
5
3
 
6
4
  const posthtmlPlugin = () => tree => {
7
5
  const targets = new Set(['bgcolor', 'color'])
@@ -27,6 +25,6 @@ export async function sixHEX(html = '', posthtmlOptions = {}) {
27
25
  return posthtml([
28
26
  posthtmlPlugin()
29
27
  ])
30
- .process(html, merge(posthtmlOptions, posthtmlConfig))
28
+ .process(html, posthtmlOptions)
31
29
  .then(result => result.html)
32
30
  }
@@ -1,8 +1,6 @@
1
1
  import posthtml from 'posthtml'
2
2
  import get from 'lodash-es/get.js'
3
- import { defu as merge } from 'defu'
4
3
  import urlParameters from 'posthtml-url-parameters'
5
- import posthtmlConfig from '../posthtml/defaultConfig.js'
6
4
 
7
5
  export default function posthtmlPlugin(options = {}) {
8
6
  const { _options, ...parameters } = options
@@ -17,6 +15,6 @@ export async function addURLParams(html = '', options = {}, posthtmlOptions = {}
17
15
  return posthtml([
18
16
  posthtmlPlugin(options)
19
17
  ])
20
- .process(html, merge(posthtmlOptions, posthtmlConfig))
18
+ .process(html, posthtmlOptions)
21
19
  .then(result => result.html)
22
20
  }
@@ -1,8 +1,6 @@
1
1
  import postcss from 'postcss'
2
2
  import posthtml from 'posthtml'
3
3
  import get from 'lodash-es/get.js'
4
- import { defu as merge } from 'defu'
5
- import posthtmlConfig from '../posthtml/defaultConfig.js'
6
4
 
7
5
  const posthtmlPlugin = (mappings = {}) => tree => {
8
6
  if (!Object.keys(mappings).length) {
@@ -60,6 +58,6 @@ export async function useAttributeSizes(html = '', mappings = {}, posthtmlOption
60
58
  return posthtml([
61
59
  posthtmlPlugin(mappings)
62
60
  ])
63
- .process(html, merge(posthtmlOptions, posthtmlConfig))
61
+ .process(html, posthtmlOptions)
64
62
  .then(result => result.html)
65
63
  }
@@ -1,12 +1,10 @@
1
- import type { Opts } from 'string-remove-widows';
2
-
3
1
  export default interface WidowWordsConfig {
4
2
  /**
5
3
  The attribute name to use.
6
4
 
7
- @default 'prevent-widows'
5
+ @default ['prevent-widows', 'no-widows']
8
6
  */
9
- attrName?: string;
7
+ attributes?: Array<string>;
10
8
 
11
9
  /**
12
10
  Replace all widow word `nbsp;` instances with a single space.
@@ -14,45 +12,27 @@ export default interface WidowWordsConfig {
14
12
 
15
13
  @default false
16
14
  */
17
- removeWidowPreventionMeasures?: Opts['removeWidowPreventionMeasures'];
18
-
19
- /**
20
- Convert the space entity to the `targetLanguage`.
21
-
22
- @default true
23
- */
24
- convertEntities?: Opts['convertEntities'];
25
-
26
- /**
27
- Language to encode non-breaking spaces in.
28
-
29
- @default 'html'
30
- */
31
- targetLanguage?: Opts['targetLanguage'];
32
-
33
- /**
34
- Should whitespace in front of dashes (-), n-dashes (–) or m-dashes (—) be replaced with a `&nbsp;`.
35
-
36
- @default true
37
- */
38
- hyphens?: Opts['hyphens'];
15
+ createWidows?: Boolean;
39
16
 
40
17
  /**
41
18
  The minimum amount of words in a target string, in order to trigger the transformer.
42
19
 
43
20
  @default 3
44
21
  */
45
- minWordCount?: Opts['minWordCount'];
46
-
47
- /**
48
- The minimum amount non-whitespace characters in a target string, in order to trigger the transformer.
49
-
50
- @default 20
51
- */
52
- minCharCount?: Opts['minCharCount'];
22
+ minWords?: Number;
53
23
 
54
24
  /**
55
25
  Start/end pairs of strings that will prevent the transformer from removing widow words inside them.
56
- */
57
- ignore?: Opts['ignore'];
26
+
27
+ @default [
28
+ { start: '{{', end: '}}' }, // Handlebars, Liquid, Nunjucks, Twig, Jinja2, Mustache
29
+ { start: '{%', end: '%}' }, // Liquid, Nunjucks, Twig, Jinja2
30
+ { start: '<%=', end: '%>' }, // EJS, ERB
31
+ { start: '<%', end: '%>' }, // EJS, ERB
32
+ { start: '{$', end: '}' }, // Smarty
33
+ { start: '<\\?', end: '\\?>' }, // PHP
34
+ { start: '#{', end: '}' } // Pug
35
+ ]
36
+ */
37
+ ignore?: Array<{ start: string; end: string }>;
58
38
  }