Skip to content

Commit 2390f8c

Browse files
committed
refactor: shift focus from email to general purpose html
1 parent eec349e commit 2390f8c

10 files changed

Lines changed: 1247 additions & 1097 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [0.2.0] - 2026-02-16
2+
3+
## Changed
4+
5+
- Move away from Email focus, to general-purpose HTML
6+
17
## [0.1.2] - 2026-02-16
28

39
### Added

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# litehtml-rs
22

3+
[![crates.io](https://img.shields.io/crates/v/litehtml.svg)](https://crates.io/crates/litehtml)
4+
35
Rust bindings for [litehtml](https://github.com/litehtml/litehtml) -- a lightweight HTML/CSS rendering engine.
46

57
## Crates
@@ -15,7 +17,8 @@ The `litehtml` crate has these feature flags:
1517

1618
- **`vendored`** (default) -- compile litehtml from bundled source. Disable to link against a system-installed litehtml (set `LITEHTML_DIR` or ensure headers/lib are on the search path).
1719
- **`pixbuf`** -- CPU-based pixel buffer backend using `tiny-skia` and `cosmic-text`. Gives you `PixbufContainer` and `render_to_rgba()`.
18-
- **`email`** -- Email preprocessing pipeline: encoding detection, HTML sanitization, `data:`/`cid:` image resolution, attribute preprocessing.
20+
- **`html`** -- General-purpose HTML utilities: encoding detection, sanitization, `data:`/`cid:` URI resolution, legacy attribute preprocessing, and a `prepare_html` pipeline.
21+
- **`email`** -- Email-specific defaults on top of `html`: `EMAIL_MASTER_CSS` and a `prepare_email_html` convenience wrapper.
1922

2023
## Usage
2124

@@ -45,7 +48,7 @@ With direnv (GUIX -- see `.envrc`):
4548

4649
```bash
4750
direnv allow
48-
cargo test --workspace --features 'litehtml/pixbuf,litehtml/email'
51+
cargo test --workspace --features 'litehtml/pixbuf,litehtml/html'
4952
```
5053

5154
Without direnv:
@@ -72,18 +75,30 @@ cargo run --example render --features pixbuf -p litehtml -- examples/email.html
7275

7376
Scroll with mouse wheel, arrow keys, Page Up/Down, Home/End. Escape to close. Optional second argument sets the viewport width (default 800).
7477

75-
## Email rendering
78+
## HTML preprocessing
7679

77-
The `email` feature provides a full preprocessing pipeline for rendering email HTML:
80+
The `html` feature provides a full preprocessing pipeline for rendering HTML:
7881

7982
```rust
80-
use litehtml::email::{prepare_email_html, EMAIL_MASTER_CSS};
83+
use litehtml::html::{prepare_html, sanitize_html, decode_html};
8184

82-
let prepared = prepare_email_html(raw_bytes, Some(&cid_resolver));
85+
let prepared = prepare_html(raw_bytes, Some(&cid_resolver), None);
8386
// prepared.html -- sanitized UTF-8 HTML
8487
// prepared.images -- resolved data:/cid: images
8588
```
8689

87-
This handles encoding detection (UTF-8, Windows-1252, ISO-8859-1), strips dangerous elements (`<script>`, `<iframe>`, event handlers), resolves inline images, and preprocesses legacy email attributes (`bgcolor` on `<body>`, `cellpadding`).
90+
This handles encoding detection (UTF-8, Windows-1252, ISO-8859-1), strips dangerous elements (`<script>`, `<iframe>`, event handlers), resolves inline images, and preprocesses legacy attributes (`bgcolor` on `<body>`, `cellpadding`).
91+
92+
Remote image fetching is off by default. Pass a `url_fetcher` closure as the third argument to opt in with your own HTTP client.
93+
94+
## Email rendering
95+
96+
The `email` feature adds email-specific defaults on top of `html`:
97+
98+
```rust
99+
use litehtml::email::{prepare_email_html, EMAIL_MASTER_CSS};
100+
101+
let prepared = prepare_email_html(raw_bytes, Some(&cid_resolver), None);
102+
```
88103

89-
Remote image fetching is off by default - tracking pixels are the norm in marketing email. Pass a `url_fetcher` closure to `prepare_email_html` to opt in with your own HTTP client.
104+
`EMAIL_MASTER_CSS` provides an email user-agent stylesheet (body reset, responsive images, table normalization, MSO workarounds).

litehtml-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[package]
22
name = "litehtml-sys"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "MIT AND BSD-3-Clause AND Apache-2.0"
66
authors = ["Franz Geffke <mail@gofranz.com>"]
77
description = "Raw FFI bindings for litehtml (C++ HTML/CSS rendering engine)"
88
repository = "https://github.com/franzos/litehtml-rs"
99
keywords = ["litehtml", "html", "css", "ffi", "rendering"]
1010
categories = ["external-ffi-bindings", "rendering"]
11+
readme = "README.md"
1112
exclude = ["tests/"]
1213

1314
[features]

litehtml-sys/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# litehtml-sys
2+
3+
[![crates.io](https://img.shields.io/crates/v/litehtml-sys.svg)](https://crates.io/crates/litehtml-sys)
4+
5+
Raw FFI bindings for [litehtml](https://github.com/litehtml/litehtml) — a lightweight C++ HTML/CSS rendering engine.
6+
7+
This crate provides auto-generated bindings via `bindgen` through a C wrapper (litehtml is C++). For a safe Rust API, use the [`litehtml`](https://crates.io/crates/litehtml) crate instead.
8+
9+
## Features
10+
11+
- **`vendored`** (default) — compile litehtml from bundled source
12+
- Disable to link against a system-installed litehtml (set `LITEHTML_DIR` or ensure headers/lib are on the search path)
13+
14+
## Requirements
15+
16+
C++17 compiler and `clang` (for bindgen).

litehtml/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
[package]
22
name = "litehtml"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "MIT"
66
authors = ["Franz Geffke <mail@gofranz.com>"]
77
description = "Safe Rust bindings for litehtml — a lightweight HTML/CSS rendering engine"
88
repository = "https://github.com/franzos/litehtml-rs"
99
keywords = ["litehtml", "html", "css", "rendering", "email"]
1010
categories = ["rendering", "web-programming"]
11+
readme = "README.md"
1112
exclude = ["tests/", "examples/"]
1213

1314
[features]
1415
default = ["vendored"]
1516
vendored = ["litehtml-sys/vendored"]
1617
pixbuf = ["tiny-skia", "cosmic-text", "image"]
17-
email = ["encoding_rs", "base64"]
18+
html = ["encoding_rs", "base64"]
19+
email = ["html"]
1820

1921
[dependencies]
20-
litehtml-sys = { path = "../litehtml-sys", version = "0.1.0", default-features = false }
22+
litehtml-sys = { path = "../litehtml-sys", version = "0.2.0", default-features = false }
2123
log = "0.4"
2224
tiny-skia = { version = "0.11", optional = true }
2325
cosmic-text = { version = "0.14", optional = true }

litehtml/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# litehtml
2+
3+
[![crates.io](https://img.shields.io/crates/v/litehtml.svg)](https://crates.io/crates/litehtml)
4+
5+
Safe Rust bindings for [litehtml](https://github.com/litehtml/litehtml) — a lightweight HTML/CSS rendering engine.
6+
7+
## Features
8+
9+
- **`vendored`** (default) — compile litehtml from bundled source
10+
- **`pixbuf`** — CPU-based pixel buffer rendering via `tiny-skia` and `cosmic-text`
11+
- **`html`** — encoding detection, sanitization, URI resolution, legacy attribute preprocessing
12+
- **`email`** — email-specific defaults on top of `html`
13+
14+
## Quick start
15+
16+
```rust
17+
use litehtml::html::prepare_html;
18+
19+
let prepared = prepare_html(raw_bytes, None, None);
20+
// prepared.html — sanitized UTF-8 HTML
21+
// prepared.images — resolved data:/cid: images
22+
```
23+
24+
See the [repository](https://github.com/franzos/litehtml-rs) for full documentation and examples.

0 commit comments

Comments
 (0)