Package detail

html-crush

codsen188.8kMIT6.0.22

Minify email templates

breaks, crush, css, email

readme

html-crush

Minify email templates

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence playground

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 4.2.0 (npm i html-crush@4.2.0).

npm i html-crush

Quick Take

import { strict as assert } from "assert";

import { crush, defaults, version } from "html-crush";

assert.equal(
  crush(
    `<table width="100" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      hi
    </td>
  </tr>
</table>`,
    { removeLineBreaks: true },
  ).result,
  `<table width="100" border="0" cellpadding="0" cellspacing="0"><tr><td> hi
</td></tr></table>`,
);

Documentation

Please visit codsen.com for a full description of the API. Also, try the GUI playground.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2025 Roy Revelt and other contributors.

ok codsen star

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

6.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

5.0.22 (2022-08-02)

Fixed

  • export Opts and Res types (a91c313)

5.0.16 (2022-04-18)

Fixed

5.0.0 (2021-09-09)

Fixed

  • tweaks to the line length calculation (4ec1fe2)

Features

  • avoid two closing curlies in a sequence (b7293b0), closes #16
  • migrate to ES Modules (8c9d95d)

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

4.2.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

4.1.9 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

4.1.5 (2021-03-28)

Fixed

  • retain the same type of line endings as the input (b171628)

4.1.0 (2021-02-27)

Features

  • single line break to be replaced with a single space (020c26b), closes #3

4.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)
  • correct the line length calculation around inline tags (073f7a5)

4.0.0 (2021-01-23)

Features

BREAKING CHANGES

  • there are no changes to the API, but just for safety, we're bumping major

2.0.5 (2020-09-15)

Fixed

  • improve CRLF line ending recognition (ff3e3e7)

2.0.0 (2020-07-04)

Fixed

  • fix typo in the output, in log.timeTakenInMilliseconds (48debda)

Features

  • opts.removeHTMLComments (2e51439)
  • add recognition for outlook conditionals (61f61c1)
  • crop tighter around conditional comments (cbc7383)
  • report applicableOpts in the output (fd3c879)

BREAKING CHANGES

  • in output, log.timeTakenInMiliseconds is now called log.timeTakenInMilliseconds (two l's)

1.9.35 (2020-05-24)

Fixed

  • fixes the pre, code, CDATA and other code chunk skipping (ec0408a), closes #29

1.9.0 (2019-09-14)

Features

  • don't remove space in front of !important within HTML conditionals (e997f51)

Davide Riva reported on emailgeeks slack that space in front of !important should not be removed, for example:

<!--[if lte mso 11]>
  <style type="text/css">
    .class {
      width: 100% !important;
    }
  </style>
<![endif]-->

That's now implemented.

1.8.5 (2019-09-04)

Fixed

  • stop breaking <!--<![endif]--> into two parts, in front of <![endif] (af421c7)

1.8.3 (2019-08-24)

Fixed

  • adding one more breaking point for insurance, thanks Mark Robbins (b21651b)

1.8.0 (2019-08-08)

Fixed

  • previously inner tag whitespace removal was too lax, risking false positives (ab59492)
  • update the program's name on throw error reports (abd093a)

Features

  • don't minify whitespace around brackets if there is a number on either side (21ea2ff)

1.7.0 (2019-07-24)

Features

  • Don't delete whitespace between closing curly brace and opening curly brace (ef5efaa)

1.6.0 (2019-07-15)

Fixed

  • Fix the rare cases where state of being within style tag was not terminated properly (fefc206), closes #11

Features

  • Inline tag recognition and proper spacing (ad97faf)

1.5.0 (2019-06-29)

Features

1.4.0 (2019-06-21)

Features

  • Break to the right of opening style tag if breaking on the left is turned on (67ca84a)

1.3.0 (2019-06-18)

Features

  • opts.reportProgressFuncFrom and opts.reportProgressFuncTo (4ebf439)
  • Re-distribute the ratio of progress reported during main and final tasks (1e80408)

1.2.0 (2019-06-01)

Features

  • Delete leading whitespace inside inline CSS (614d11b)

1.1.0 (2019-06-01)

Features

  • Inline CSS minification (0518f05)
  • Only replace line breaks when result will be smaller in size, not the same (a431686)

1.0.11 (2019-04-06)

Fixed

  • Algorithm improvement not to break in front of </a> to prevent accidentally adding new spaces (8939654)

0.8.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

0.7.0 (2019-01-11)

  • Add one more tag before which there will be a line break (4f00871)

0.6.0 (2018-12-26)

  • Add licence block at the top of built files in dist/ folder (cb2c259)
  • Add more logging for doNothing state (25262e5)
  • Do not touch CDATA blocks (920e9d9)
  • Don't minify script tags contents (557e8fa)
  • Don't touch code within pre-code blocks (d32c092)
  • Fetch a handful of real websites and minify them for tests (f7e8153)
  • Remove whitespace within <script> blocks, in front of </script> (d1efb20)
  • Treat the whitespace in front of <script> (75d85dc)

0.5.0 (2018-12-14)

  • Added licence banner at the top of each built file (all files in dist/ folder)
  • Improved readme file

0.4.0 (2018-12-13)

  • Delete whitespace within <script> tag, before closing </script>.
  • Added unit tests minifying a handful of real-world websites. If URL fetch succeeds and source HTML is a string and not an empty-one, we minify with couple settings and measure, are results less than or equal to the original sources.

0.3.0 (2018-12-12)

  • Improvements to whitespace control in front of <script> tag when some options are on.

0.2.0 (2018-12-11)

  • Program will not touch:
    • CDATA blocks
    • <pre><code>...</code></pre> blocks
    • <script> tag contents

0.1.0 (2018-12-10)

  • First public release