15 releases (4 breaking)

0.5.3 Aug 27, 2024
0.5.2 Apr 23, 2024
0.5.1 Jan 21, 2024
0.4.2 Dec 27, 2023
0.1.1 Dec 18, 2023

#57 in Value formatting

Download history 155/week @ 2024-08-23 417/week @ 2024-08-30 487/week @ 2024-09-06 760/week @ 2024-09-13 546/week @ 2024-09-20 629/week @ 2024-09-27 480/week @ 2024-10-04 547/week @ 2024-10-11 299/week @ 2024-10-18 369/week @ 2024-10-25 412/week @ 2024-11-01 324/week @ 2024-11-08 219/week @ 2024-11-15 259/week @ 2024-11-22 399/week @ 2024-11-29 216/week @ 2024-12-06

1,190 downloads per month
Used in crabsoup

MIT/Apache

25KB
566 lines

Build Status crates.io docs.rs

Tidier

This crate provides a safe abstraction over the Tidy C library.

Features

  • Currently, it only supports formatting of HTML, XHTML and XML documents.

Examples

Note: Check out the basic CLI example in the examples directory.

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>(())

Build Requirements

This crate uses tidy-sys, which generates bindings on the fly using bindgen, then compiles the tidy C library from source. Therefore you need;

  • clang: For parsing C headers to generate Rust bindings
  • A C compiler: To compile the Tidy C library
  • CMake: To configure and orchestrate compilation of the Tidy C library (it uses CMake as the build system)

You don't need to install libtidy on your system; tidy-sys vendors the source code, builds and links to it statically.

Dependencies

~3–12MB
~142K SLoC