Crate css_inline[−][src]
Expand description
css-inline
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> <head> <title>Test</title> <style>h1 { color:blue; }</style> </head> <body> <h1>Big Text</h1> </body> </html>
Will be turned into this:
<html> <head><title>Test</title></head> <body> <h1 style="color:blue;">Big Text</h1> </body> </html>
Usage
const HTML: &str = r#"<html> <head> <title>Test</title> <style>h1 { color:blue; }</style> </head> <body> <h1>Big Text</h1> </body> </html>"#; fn main() -> Result<(), css_inline::InlineError> { let inlined = css_inline::inline(HTML)?; // shortcut with default options // Do something with inlined HTML, e.g. send an email Ok(()) }
Features & Configuration
css-inline
can be configured by using CSSInliner::options()
that implements the Builder pattern:
const HTML: &str = r#"<html> <head> <title>Test</title> <style>h1 { color:blue; }</style> </head> <body> <h1>Big Text</h1> </body> </html>"#; fn main() -> Result<(), css_inline::InlineError> { let inliner = css_inline::CSSInliner::options() .load_remote_stylesheets(false) .build(); let inlined = inliner.inline(HTML); // Do something with inlined HTML, e.g. send an email Ok(()) }
inline_style_tags
. Whether to inline CSS from “style” tags. Default:true
remove_style_tags
. Remove “style” tags after inlining. Default:false
base_url
. Base URL to resolve relative URLs. Default:None
load_remote_stylesheets
. Whether remote stylesheets should be loaded or not. Default:true
extra_css
. Additional CSS to inline. Default:None
Re-exports
pub use error::InlineError;
Modules
Errors that may happen during inlining.
Structs
Customizable CSS inliner.
Configuration options for CSS inlining process.
A parsed URL record.
Enums
Errors that can occur during parsing.