Crate tidier

Source
Expand description

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

§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.

Re-exports§

pub use tidy_sys::TidyUseCustomTagsState as CustomTags;

Structs§

Diagnostic
A diagnostic generated by Tidy.
Doc
An HTML or XML document.
FormatOptions
Formatting options.
Indent
Indentation options for formatting.

Enums§

DiagnosticLevel
The severity of a diagnostic.
Error
An error generated during parsing or formatting.
LineEnding
The line ending to use while formatting.

Functions§

format
A convenience function for Doc::format.
format_bytes
A convenience function for Doc::format_bytes.
format_bytes_to
A convenience function for Doc::format_bytes_to.
format_to
A convenience function for Doc::format_to.

Type Aliases§

Result