@ ciolabs/ 保温- comment- 白空间
保留 HTML 注释周围是否有空白.
HTML格式化器并不总是能正确处理 HTML 注释. 此包试图正确维护 HTML 注释周围的空白.
一些已知的问题:
- https://github.com/beautify-web/js-beautify/issues/1301 (中文(简体) )
- https://github.com/beautify-web/js-beautify/issues/1823 (中文(简体) )
安装
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。 。 。 .
选项
RestoreOptionsqq 默认为{ restoreInline: true }
如何恢复注释白空间的配置 .
接受 restoreInline如果 true,原本被内置的注释(即不在其自行)会被恢复为内置. 否则,它将接受新线的位置.
类型
注释数据
interface CommentData {
leadingWhitespace: string;
trailingWhitespace: string;
hasLeadingWhitespace: boolean;
hasTrailingWhitespace: boolean;
}
恢复选项
interface RestoreOptions {
restoreInline: boolean;
}