Skip to content

Commit

Permalink
Replace htmlnano with html-crush
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Brazeilles committed Dec 3, 2024
1 parent ba8b2c6 commit 087cadf
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 461 deletions.
3 changes: 1 addition & 2 deletions packages/mjml-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"dependencies": {
"@babel/runtime": "^7.23.9",
"cheerio": "1.0.0-rc.12",
"cssnano": "^7.0.1",
"detect-node": "^2.0.4",
"htmlnano": "^2.1.1",
"html-crush": "^4.2.0",
"juice": "^11.0.0",
"lodash": "^4.17.21",
"mjml-parser-xml": "5.0.0-alpha.6",
Expand Down
12 changes: 3 additions & 9 deletions packages/mjml-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'path'
import juice from 'juice'
import { load } from 'cheerio'
import prettier from 'prettier'
import minifier from 'htmlnano'
import { crush } from 'html-crush'

import MJMLParser from 'mjml-parser-xml'
import MJMLValidator, {
Expand Down Expand Up @@ -396,18 +396,12 @@ export default async function mjml2html(mjml, options = {}) {
content = await prettier.format(content, {
parser: 'html',
printWidth: 240,
singleQuote: true,
})
}

if (minify) {
content = await minifier
.process(content, {
collapseWhitespace: true,
minifyCSS: false,
removeEmptyAttributes: true,
...minifyOptions,
})
.then((res) => res.html)
content = crush(content, { ...options.minifyOptions }).result
}

return {
Expand Down
13 changes: 4 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ const xml = `
<mjml>
<mj-head>
<mj-attributes>
<mj-all
padding="0px"
/>
<mj-wrapper
background-color="yellow"
padding="80px"
/>
<mj-all font-family="'Source Sans 3', Arial, sans-serif" font-size="16px" line-height="1.4" color="#0f3549" />
</mj-attributes>
</mj-head>
<mj-body>
Expand All @@ -35,8 +29,11 @@ async function run() {
console.time('mjml2html')
const { html } = await mjml2html(xml, {
minify: true,
beautify: false,
})

console.log(html)

console.timeEnd('mjml2html')

if (process.argv.includes('--open')) {
Expand All @@ -50,8 +47,6 @@ async function run() {

open(testFile)
}

await run()
}

run()
Loading

0 comments on commit 087cadf

Please sign in to comment.