File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55### Added
66
77- ` CSSInliner ` and customization options. [ #9 ] ( https://github.com/Stranger6667/css-inline/issues/9 )
8+ - Option to remove "style" tags. [ #11 ] ( https://github.com/Stranger6667/css-inline/issues/11 )
89
910### Changed
1011
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 {};
98+ //! let options = css_inline::InlineOptions { remove_style_tags: true };
9999//! let inliner = css_inline::CSSInliner::new(options);
100100//! let inlined = inliner.inline(HTML)?;
101101//! // Do something with inlined HTML, e.g. send an email
@@ -154,12 +154,17 @@ impl Rule {
154154
155155/// Configuration options for CSS inlining process.
156156#[ derive( Debug ) ]
157- pub struct InlineOptions { }
157+ pub struct InlineOptions {
158+ /// Remove "style" tags after inlining
159+ pub remove_style_tags : bool ,
160+ }
158161
159162impl Default for InlineOptions {
160163 #[ inline]
161164 fn default ( ) -> Self {
162- InlineOptions { }
165+ InlineOptions {
166+ remove_style_tags : false ,
167+ }
163168 }
164169}
165170
@@ -216,6 +221,9 @@ impl CSSInliner {
216221 }
217222 }
218223 }
224+ if self . options . remove_style_tags {
225+ style_tag. as_node ( ) . detach ( )
226+ }
219227 }
220228 let mut out = vec ! [ ] ;
221229 document. serialize ( & mut out) ?;
Original file line number Diff line number Diff line change 1- use css_inline:: inline;
1+ use css_inline:: { inline, CSSInliner , InlineOptions } ;
22
33macro_rules! html {
44 ( $style: expr, $body: expr) => {
@@ -100,3 +100,14 @@ fn invalid_rule() {
100100 assert ! ( result. is_err( ) ) ;
101101 assert_eq ! ( result. unwrap_err( ) . to_string( ) , "Invalid @ rule: wrong" )
102102}
103+
104+ #[ test]
105+ fn remove_style_tag ( ) {
106+ 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) ;
111+ let result = inliner. inline ( & html) . unwrap ( ) ;
112+ assert_eq ! ( result, "<html><head><title>Test</title></head><body><h1 style=\" background-color: blue;\" >Hello world!</h1></body></html>" )
113+ }
You can’t perform that action at this time.
0 commit comments