1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
//! A CSS inliner for making emails. extern crate kuchiki; extern crate servo_css_parser; #[macro_use] extern crate html5ever; #[macro_use] extern crate maplit; mod rules; pub use rules::*; mod hash; pub use hash::*; mod property_declaration_value; mod options; pub use options::Options as OptionsRequired; pub use options::default::*; mod settings; pub use settings::Settings as SettingsRequired; pub use settings::default::*; mod eyeliner; pub use eyeliner::*; pub mod traits; use traits::*; /// Returns a string of HTML with CSS inlined. /// /// # Arguments /// /// * `html` - A string of HTML to have CSS inlined into. Any `<style />` tags will have their /// styles parsed and processed. /// /// * `css` - An optional string of additional CSS to be inlined that is added _before_ the /// `<style />` tags in the `html` are parsed. /// /// * `options` - An optional instance of `Options`. /// /// * `settings` - An optional instance of `Settings`. /// /// # Remarks /// /// Convenient function to inline HTML and CSS the same way as Juice. /// /// # Examples /// /// ``` /// use eyeliner::inline; /// /// let html = r#" /// <!DOCTYPE html> /// <html> /// <head> /// <title>Test</title> /// </head> /// <body> /// <h1>Hello, world!</h1> /// <p>I <span class="red">love</span> Rust!</p> /// </body> /// </html> /// "#; /// /// let css = r#" /// .red { /// color: red; /// } /// "#; /// /// let fixture = r#" /// <!DOCTYPE html> /// <html> /// <head> /// <title>Test</title> /// </head> /// <body> /// <h1>Hello, world!</h1> /// <p>I <span class="red" style="color: red;">love</span> Rust!</p> /// </body> /// </html> /// "#; /// /// assert_eq!( /// inline(fixture, None, None, None), // Just used to format the HTML the same way /// inline(html, Some(css), None, None), /// ); /// ``` pub fn inline(html: &str, css: Option<&str>, options: Option<Options>, settings: Option<Settings>) -> String { Eyeliner::new(html, css, options, settings) .collect_rules() .apply_rules() .apply_width_attributes() .apply_height_attributes() .apply_table_element_attributes() .insert_preserved_css() .to_string() }