@ciolabs/html-process-conditional-comments

中文文档
0.0.4发布于 2026/02/20Apache-2.0 WITH Commons-ClauseTypeScriptESM + CJS构建来源已验证近 30 天下载 2.2万

Makes it easy to safely process HTML inside of conditional comments

原始使用文档
文档目录8 节
  1. Why?
  2. Install
  3. Usage
  4. API
  5. preprocess(source: string) => string
  6. postprocess(source: string) => string
  7. getEmbeddedDocument(source: string) => string
  8. TypeScript Support

@ciolabs/process-conditional-comments

Makes it easy to safely process HTML inside of conditional comments

Why?

Conditional comments are a way to target specific email clients. For example, you can use conditional comments to target Outlook 2007 and below. However, conditional comments are literally HTML comments, so you can't parse them with a normal HTML parser. This library makes it easy to safely process HTML inside of conditional comments by revealing the HTML content and wrapping the HTML back inside of the conditional comments when the processing is complete.

Install

npm install @ciolabs/process-conditional-comments

Usage

import { preprocess, postprocess } from '@ciolabs/process-conditional-comments';

const html = `
  <!--[if mso]>
    <div>hello</div>
  <![endif]-->
`;

const processed = preprocess(html);

// now parse the HTML and do whatever you want with it
const doc = new HtmlMod(processed);

// do some manipulation
doc.querySelector('div').innerHTML = 'world';

// now postprocess the HTML
const postprocessed = postprocess(doc.toString());

console.log(postprocessed);
//=> <!--[if mso]>
//=>   <div>world</div>
//=> <![endif]-->

API

preprocess(source: string) => string

Preprocesses the HTML string by revealing the HTML content inside of conditional comments. This is the first step in processing HTML inside of conditional comments.

Example:

<!--[if mso]>HTML<![endif]-->

becomes

<!--[if mso]>__PROCESS_CONDITIONAL_COMMENTS-->HTML<!--__PROCESS_CONDITIONAL_COMMENTS<![endif]-->

postprocess(source: string) => string

Postprocesses the HTML string by wrapping the HTML content inside of conditional comments. This is the last step in processing HTML inside of conditional comments.

Reverts the changes made by preprocess().

getEmbeddedDocument(source: string) => string

Gets the full embedded document, replacing the conditional comments with whitespace of equal length.

This is useful when you want to extract just the HTML content without the conditional comment markers, while preserving the original document structure and character positions.

TypeScript Support

This package is built with TypeScript and provides full type definitions.

版本与发布记录

@ciolabs/html-process-conditional-comments 共发布 5 个版本,首次发布于 2025/09/19;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.4latest2026/02/208 个月前
0.0.32026/02/208 个月前
0.0.22025/11/1811 个月前
0.0.12025/09/191.1 年前
0.0.02025/09/191.1 年前

关于 @ciolabs/html-process-conditional-comments 的常见问题

@ciolabs/html-process-conditional-comments 是什么?

Makes it easy to safely process HTML inside of conditional comments

如何安装 @ciolabs/html-process-conditional-comments?

在项目目录运行 npm install @ciolabs/html-process-conditional-comments,或使用 pnpm add / yarn add / bun add。

@ciolabs/html-process-conditional-comments 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ciolabs/html-process-conditional-comments 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ciolabs/html-process-conditional-comments 可以商用吗?

@ciolabs/html-process-conditional-comments 使用 Apache-2.0 WITH Commons-Clause 许可。声明的许可为 Apache-2.0 WITH Commons-Clause,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@ciolabs/html-process-conditional-comments 的下载量有多少?

根据 npm 官方下载统计,@ciolabs/html-process-conditional-comments 在 2026/10/10 – 2026/11/08 这 30 天内被下载 22,424 次,日均约 747 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ciolabs/html-process-conditional-comments 还在维护吗?

最新版本 0.0.4 发布于 2026/02/20(8 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/09/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。