@ciolabs/html-preserve-comment-whitespace

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

保留 HTML 注释周围是否有空白

中文使用文档
文档目录8 节
  1. 安装
  2. 使用量
  3. API 密码
  4. 保存( html)
  5. 还原(html、注释、选项)
  6. 类型
  7. 注释数据
  8. 恢复选项

@ ciolabs/ 保温- comment- 白空间

保留 HTML 注释周围是否有空白.

HTML格式化器并不总是能正确处理 HTML 注释. 此包试图正确维护 HTML 注释周围的空白.

一些已知的问题:

安装

npm install @ciolabs/preserve-comment-whitespace

使用量

import { preserve, restore } from '@ciolabs/preserve-comment-whitespace';
import beautify from 'js-beautify';

const html = `<div><div><!-- my html comment --></div></div>`;

const comments = preserve(html);
const formatted = beautify.html(html);
//=> <div>\n    <div>\n        <!-- my html comment -->\n    </div>\n</div>
const formattedAndRestored = restore(formatted, comments);
//=> <div>\n    <div><!-- my html comment --></div>\n</div>

API 密码

保存( html)

返回包含描述 HTML 注释的对象的矩阵.

还原(html、注释、选项)

返回 HTML 注释周围的空白区域恢复的字符串.

说明: 处理 preserve 财务报告和审定财务报表 restore 不应添加或删除任何评论。 如果给出的评论数量与给定的HTML中找到的评论数量不符, restore 将返回未处理的指定字符串.

(简体中文)

string 所需时间

HTML 在任何会影响白空间的格式之后的字符串 .

评论

CommentData[] qq 默认为 []

阵列从 preserve。 。 。 .

选项

RestoreOptions qq 默认为 { restoreInline: true }

如何恢复注释白空间的配置 .

接受 restoreInline如果 true,原本被内置的注释(即不在其自行)会被恢复为内置. 否则,它将接受新线的位置.

类型

注释数据

interface CommentData {
  leadingWhitespace: string;
  trailingWhitespace: string;
  hasLeadingWhitespace: boolean;
  hasTrailingWhitespace: boolean;
}

恢复选项

interface RestoreOptions {
  restoreInline: boolean;
}

版本与发布记录

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

版本发布日期距今
0.0.3latest2026/02/208 个月前
0.0.22026/02/208 个月前
0.0.12025/09/191.1 年前
0.0.02025/09/191.1 年前

关于 @ciolabs/html-preserve-comment-whitespace 的常见问题

@ciolabs/html-preserve-comment-whitespace 是什么?

保留 HTML 注释周围是否有空白

如何安装 @ciolabs/html-preserve-comment-whitespace?

在项目目录运行 npm install @ciolabs/html-preserve-comment-whitespace,或使用 pnpm add / yarn add / bun add。

@ciolabs/html-preserve-comment-whitespace 支持 TypeScript 吗?

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

@ciolabs/html-preserve-comment-whitespace 支持 ESM 还是 CommonJS?

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

@ciolabs/html-preserve-comment-whitespace 可以商用吗?

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

@ciolabs/html-preserve-comment-whitespace 的下载量有多少?

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

@ciolabs/html-preserve-comment-whitespace 还在维护吗?

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