htmlfixinator 0.1.0

A composable HTML transformation library with filters for cleaning, modifying, and standardizing HTML content
Documentation
# HTMLFixinator

A Rust library for cleaning and transforming HTML content through a composable filter system. HTMLFixinator provides a set of filters that can be used individually or chained together to modify HTML documents.

## Features

- ๐Ÿ” **Attribute Filter**: Remove specific HTML attributes while preserving others
- ๐Ÿ—‘๏ธ **Comment Filter**: Strip HTML comments from the document
- ๐Ÿ“ฆ **Element Filter**: Remove or unwrap specific HTML elements
- ๐Ÿงน **Empty Filter**: Remove empty elements while preserving non-empty ones
- ๐Ÿ”— **URL Filter**: Convert relative URLs to absolute URLs
- โ›“๏ธ **Filter Chain**: Combine multiple filters for complex transformations
- ๐ŸŽฏ **Case-insensitive**: All filters work case-insensitively for robustness

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
htmlfixinator = { version = "0.1.0" }
```

Or run this command:
```bash
cargo add htmlfixinator
```

## Usage

### Basic Example

```rust
use htmlfixinator::{
    filters::{Filter, FilterTrait},
    string_to_node, node_to_string,
};

// Create a filter to remove class and style attributes
let filter = Filter::attribute(&["class", "style"]);

// Apply the filter to some HTML
let html = r#"<div class="test" style="color: red;">Content</div>"#;
let doc = string_to_node(html);
let result = filter.apply(doc);

assert_eq!(node_to_string(result), "<div>Content</div>");
```

### Chaining Filters

```rust
use htmlfixinator::{
    filters::{Filter, FilterChain, FilterTrait},
    string_to_node, node_to_string,
};

// Create a chain of filters
let chain = FilterChain::new()
    .add(Filter::comment())           // Remove comments
    .add(Filter::empty())            // Remove empty elements
    .add(Filter::attribute(&["class"])); // Remove class attributes

let html = r#"<!-- Comment --><div class="test"><span></span><p>Content</p></div>"#;
let doc = string_to_node(html);
let result = chain.apply(doc);

assert_eq!(node_to_string(result), "<div><p>Content</p></div>");
```

## Available Filters

### AttributeFilter

Removes specified attributes from all elements.

```rust
use htmlfixinator::filters::Filter;

let filter = Filter::attribute(&["class", "style"]);
```

### CommentFilter

Removes all HTML comments from the document.

```rust
use htmlfixinator::filters::Filter;

let filter = Filter::comment();
```

### ElementFilter

Either removes elements completely or unwraps them (removes the element but keeps its content).

```rust
use htmlfixinator::filters::Filter;

// Remove mode
let filter = Filter::element(&["script", "style"], false);

// Unwrap mode
let filter = Filter::element(&["div", "span"], true);
```

### EmptyFilter

Removes elements that have no content (preserves elements with `<img>` tags).

```rust
use htmlfixinator::filters::Filter;

let filter = Filter::empty();
```

### RelativeToAbsoluteFilter

Converts relative URLs in href attributes to absolute URLs.

```rust
use htmlfixinator::filters::Filter;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let filter = Filter::relabs("https://example.com/path/")?;
    Ok(())
}
```

## License

This project is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.en.html).