File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77- ` CSSInliner ` and customization options. [ #9 ] ( https://github.com/Stranger6667/css-inline/issues/9 )
88- Option to remove "style" tags. [ #11 ] ( https://github.com/Stranger6667/css-inline/issues/11 )
9+ - ` CSSInliner::compact() ` constructor for producing smaller HTML output.
910
1011### Changed
1112
Original file line number Diff line number Diff line change 9595//! </html>"#;
9696//!
9797//!fn main() -> Result<(), css_inline::InlineError> {
98- //! let options = css_inline::InlineOptions { remove_style_tags: true };
99- //! let inliner = css_inline::CSSInliner::new(options);
98+ //! let inliner = css_inline::CSSInliner::compact();
10099//! let inlined = inliner.inline(HTML)?;
101100//! // Do something with inlined HTML, e.g. send an email
102101//! Ok(())
@@ -159,6 +158,16 @@ pub struct InlineOptions {
159158 pub remove_style_tags : bool ,
160159}
161160
161+ impl InlineOptions {
162+ /// Options for "compact" HTML output
163+ #[ inline]
164+ pub fn compact ( ) -> Self {
165+ InlineOptions {
166+ remove_style_tags : true ,
167+ }
168+ }
169+ }
170+
162171impl Default for InlineOptions {
163172 #[ inline]
164173 fn default ( ) -> Self {
@@ -181,6 +190,15 @@ impl CSSInliner {
181190 CSSInliner { options }
182191 }
183192
193+ /// Inliner, that will produce "compact" HTML.
194+ /// For example, "style" tags will be removed.
195+ #[ inline]
196+ pub fn compact ( ) -> Self {
197+ CSSInliner {
198+ options : InlineOptions :: compact ( ) ,
199+ }
200+ }
201+
184202 /// Inline CSS styles from <style> tags to matching elements in the HTML tree.
185203 #[ inline]
186204 pub fn inline ( & self , html : & str ) -> Result < String , InlineError > {
Original file line number Diff line number Diff line change 1- use css_inline:: { inline, CSSInliner , InlineOptions } ;
1+ use css_inline:: { inline, CSSInliner } ;
22
33macro_rules! html {
44 ( $style: expr, $body: expr) => {
@@ -104,10 +104,7 @@ fn invalid_rule() {
104104#[ test]
105105fn remove_style_tag ( ) {
106106 let html = html ! ( "h1 {background-color: blue;}" , "<h1>Hello world!</h1>" ) ;
107- let options = InlineOptions {
108- remove_style_tags : true ,
109- } ;
110- let inliner = CSSInliner :: new ( options) ;
107+ let inliner = CSSInliner :: compact ( ) ;
111108 let result = inliner. inline ( & html) . unwrap ( ) ;
112109 assert_eq ! ( result, "<html><head><title>Test</title></head><body><h1 style=\" background-color: blue;\" >Hello world!</h1></body></html>" )
113110}
You can’t perform that action at this time.
0 commit comments