14 个版本 (4 个破坏性更新)

0.5.2 2024 年 4 月 23 日
0.5.1 2024 年 1 月 21 日
0.4.2 2023 年 12 月 27 日
0.3.3 2023 年 12 月 23 日
0.1.1 2023 年 12 月 18 日

#104 in 值格式化


crabsoup 中使用

MIT/Apache

25KB
566 代码行

Build Status crates.io docs.rs

Tidier

此 crate 提供了对 Tidy C 库的安全抽象。

功能

  • 目前,它仅支持格式化 HTML、XHTML 和 XML 文档。

示例

注意:查看 示例目录 中的基本 CLI 示例。

use tidier::{Doc, FormatOptions, Indent};

let html = "<html>
<head><title>Tidy Usage Example</title></head>
<body><p>Usage example</p></body>
</html>";

let opts = FormatOptions {
	wrap: 60,
	strip_comments: true,
	indent: Indent {
		tabs: true,
		..Indent::DEFAULT
	},
	..FormatOptions::DEFAULT
};

// Alternatively
let opts = FormatOptions::new()
	.tabs(true)
	.strip_comments(true)
	.wrap(60);

let doc = Doc::new(html, false)?;
let s1 = doc.format(&opts)?;

// Or for short:
let s2 = tidier::format(html, false, &opts)?;

assert_eq!(s1, s2);

# Ok::<_, tidier::Error>(())

构建需求

此 crate 使用 tidy-sys,它使用 bindgen 动态生成绑定,然后从源代码编译 tidy C 库。因此你需要;

  • clang:用于解析 C 头文件以生成 Rust 绑定
  • C 编译器:用于编译 Tidy C 库
  • CMake:用于配置和编排 Tidy C 库的编译(它使用 CMake 作为构建系统)

你不需要在你的系统上安装 libtidy;tidy-sys 提供源代码,构建并静态链接到它。

依赖关系

~2–11MB
~118K SLoC