css-inline

ci Crates.io docs.rs

A crate for inlining CSS into HTML documents. When you send HTML emails you need to use "style" attributes instead of "style" tags.

For example, this HTML:

html <html> <head> <title>Test</title> <style>h1 { color:blue; }</style> </head> <body> <h1>Big Text</h1> </body> </html>

Will be turned into this:

html <html> <head><title>Test</title></head> <body> <h1 style="color:blue;">Big Text</h1> </body> </html>

To use it in your project add the following line to your dependencies section in project's Cargo.toml file:

toml css-inline = "0.1"

Usage

```rust use css_inline;

const HTML: &str = r#" Test

Big Text

"#;

fn main() -> Result<(), cssinline::InlineError> { let inlined = cssinline::inline(HTML)?; // Do something with inlined HTML, e.g. send an email Ok(()) } ```

Features

css-inline does minimum work by default:

It also loads external stylesheets via network or filesystem, but this behavior is configurable.

Configuration

css-inline can be configured by using InlineOptions and CSSInliner:

```rust use css_inline;

fn main() -> Result<(), cssinline::InlineError> { let options = cssinline::InlineOptions { loadremotestylesheets: false, ..Default::default() }; let inliner = css_inline::CSSInliner(options); let inlined = inliner.inline(HTML); // Do something with inlined HTML, e.g. send an email Ok(()) } ```