File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 6
6
7
7
- ` CSSInliner ` and customization options. [ #9 ] ( https://github.com/Stranger6667/css-inline/issues/9 )
8
8
- Option to remove "style" tags. [ #11 ] ( https://github.com/Stranger6667/css-inline/issues/11 )
9
+ - ` CSSInliner::compact() ` constructor for producing smaller HTML output.
9
10
10
11
### Changed
11
12
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 { remove_style_tags: true };
99
- //! let inliner = css_inline::CSSInliner::new(options);
98
+ //! let inliner = css_inline::CSSInliner::compact();
100
99
//! let inlined = inliner.inline(HTML)?;
101
100
//! // Do something with inlined HTML, e.g. send an email
102
101
//! Ok(())
@@ -159,6 +158,16 @@ pub struct InlineOptions {
159
158
pub remove_style_tags : bool ,
160
159
}
161
160
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
+
162
171
impl Default for InlineOptions {
163
172
#[ inline]
164
173
fn default ( ) -> Self {
@@ -181,6 +190,15 @@ impl CSSInliner {
181
190
CSSInliner { options }
182
191
}
183
192
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
+
184
202
/// Inline CSS styles from <style> tags to matching elements in the HTML tree.
185
203
#[ inline]
186
204
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 } ;
2
2
3
3
macro_rules! html {
4
4
( $style: expr, $body: expr) => {
@@ -104,10 +104,7 @@ fn invalid_rule() {
104
104
#[ test]
105
105
fn remove_style_tag ( ) {
106
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) ;
107
+ let inliner = CSSInliner :: compact ( ) ;
111
108
let result = inliner. inline ( & html) . unwrap ( ) ;
112
109
assert_eq ! ( result, "<html><head><title>Test</title></head><body><h1 style=\" background-color: blue;\" >Hello world!</h1></body></html>" )
113
110
}
You can’t perform that action at this time.
0 commit comments