Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/insomnimus/tidier
A Rust library for formatting HTML, XHTML and XML - Uses libtidy
https://github.com/insomnimus/tidier
Last synced: about 1 month ago
JSON representation
A Rust library for formatting HTML, XHTML and XML - Uses libtidy
- Host: GitHub
- URL: https://github.com/insomnimus/tidier
- Owner: insomnimus
- License: other
- Created: 2023-12-18T22:36:09.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-08-27T12:52:28.000Z (4 months ago)
- Last Synced: 2024-08-27T14:17:14.428Z (4 months ago)
- Language: Rust
- Size: 50.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-rust - insomnimus/tidier - A library to format HTML, XHTML and XML documents. [![build badge](https://github.com/insomnimus/tidier/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/insomnimus/tidier/actions) (Libraries / Markup language)
README
[![Build Status](https://github.com/insomnimus/tidier/actions/workflows/main.yml/badge.svg)](https://github.com/insomnimus/tidier/actions)
[![crates.io](https://img.shields.io/crates/v/tidier.svg)](https://crates.io/crates/tidier)
[![docs.rs](https://docs.rs/tidier/badge.svg)](https://docs.rs/tidier/)# Tidier
This crate provides a safe abstraction over the [Tidy](https://github.com/htacg/tidy-html5) 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](https://github.com/insomnimus/tidier/tree/main/examples).```rust
use tidier::{Doc, FormatOptions, Indent};let html = "
Tidy Usage ExampleUsage example
";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](https://crates.io/crates/tidy-sys), which generates bindings on the fly using [bindgen](https://github.com/rust-lang/rust-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.