npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ciolabs/html-email-formatter

v0.0.5

Published

Format and prettify HTML email content

Readme

@ciolabs/html-email-formatter

Format and prettify HTML email content with conditional comment support

Email HTML often contains Microsoft Outlook conditional comments (<!--[if mso]>) that need special handling during formatting. Standard HTML formatters can break these comments or misalign their indentation. This package safely formats email HTML while preserving conditional comment structure and whitespace.

Why?

When building HTML emails, you often need to include conditional comments for Microsoft Outlook compatibility:

<div>
  <!--[if mso]>
<table><tr><td>
<![endif]-->
  <p>Email content</p>
  <!--[if mso]>
</td></tr></table>
<![endif]-->
</div>

Standard HTML formatters either:

  • Break the conditional comment syntax
  • Misalign the opening and closing tags
  • Strip important whitespace around comments

This formatter handles these edge cases correctly.

Install

npm install @ciolabs/html-email-formatter

Usage

import emailFormatter from '@ciolabs/html-email-formatter';

const html = `
<div>
<!--[if mso]>
<table><tr><td>
<![endif]-->
<p>Email content</p>
<!--[if mso]>
</td></tr></table>
<![endif]-->
</div>
`;

const formatted = emailFormatter(html);
console.log(formatted);

Output:

<div>
  <!--[if mso]>
  <table>
    <tr>
      <td>
  <![endif]-->
  <p>Email content</p>
  <!--[if mso]>
      </td>
    </tr>
  </table>
  <![endif]-->
</div>

With Options

The formatter accepts options from both pretty and js-beautify:

const formatted = emailFormatter(html, {
  indent_size: 4,
  wrap_line_length: 80,
  preserve_newlines: false,
});

How It Works

  1. Temporarily closes conditional comments - Converts <!--[if mso]>content<![endif]--> to <!--[if mso]>-->content<!--<![endif]--> so formatters can process the inner HTML
  2. Preserves comment whitespace - Uses @ciolabs/html-preserve-comment-whitespace to maintain spacing around comments
  3. Formats the HTML - Runs the modified HTML through standard formatters
  4. Restores conditional comments - Converts back to original conditional comment syntax
  5. Aligns indentation - Ensures opening and closing tags have consistent indentation

API

emailFormatter(html, options?)

Formats HTML email content while preserving conditional comments.

Parameters:

Returns:

  • (string) - The formatted HTML

Common Options:

  • indent_size (number) - Number of spaces for indentation (default: 2)
  • wrap_line_length (number) - Line length before wrapping (default: 80)
  • preserve_newlines (boolean) - Whether to preserve existing newlines (default: true)
  • max_preserve_newlines (number) - Maximum consecutive newlines to preserve (default: 2)