File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 5
5
### Added
6
6
7
7
- ` 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 )
8
9
9
10
### Changed
10
11
Original file line number Diff line number Diff line change 95
95
//! </html>"#;
96
96
//!
97
97
//!fn main() -> Result<(), css_inline::InlineError> {
98
- //! let options = css_inline::InlineOptions {};
98
+ //! let options = css_inline::InlineOptions { remove_style_tags: true };
99
99
//! let inliner = css_inline::CSSInliner::new(options);
100
100
//! let inlined = inliner.inline(HTML)?;
101
101
//! // Do something with inlined HTML, e.g. send an email
@@ -154,12 +154,17 @@ impl Rule {
154
154
155
155
/// Configuration options for CSS inlining process.
156
156
#[ derive( Debug ) ]
157
- pub struct InlineOptions { }
157
+ pub struct InlineOptions {
158
+ /// Remove "style" tags after inlining
159
+ pub remove_style_tags : bool ,
160
+ }
158
161
159
162
impl Default for InlineOptions {
160
163
#[ inline]
161
164
fn default ( ) -> Self {
162
- InlineOptions { }
165
+ InlineOptions {
166
+ remove_style_tags : false ,
167
+ }
163
168
}
164
169
}
165
170
@@ -216,6 +221,9 @@ impl CSSInliner {
216
221
}
217
222
}
218
223
}
224
+ if self . options . remove_style_tags {
225
+ style_tag. as_node ( ) . detach ( )
226
+ }
219
227
}
220
228
let mut out = vec ! [ ] ;
221
229
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 } ;
2
2
3
3
macro_rules! html {
4
4
( $style: expr, $body: expr) => {
@@ -100,3 +100,14 @@ fn invalid_rule() {
100
100
assert ! ( result. is_err( ) ) ;
101
101
assert_eq ! ( result. unwrap_err( ) . to_string( ) , "Invalid @ rule: wrong" )
102
102
}
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