|
9 | 9 | //! <html>
|
10 | 10 | //! <head>
|
11 | 11 | //! <title>Test</title>
|
12 |
| -//! <style> |
13 |
| -//! h1, h2 { color:blue; } |
14 |
| -//! strong { text-decoration:none } |
15 |
| -//! p { font-size:2px } |
16 |
| -//! p.footer { font-size: 1px} |
17 |
| -//! </style> |
| 12 | +//! <style>h1 { color:blue; }</style> |
18 | 13 | //! </head>
|
19 | 14 | //! <body>
|
20 | 15 | //! <h1>Big Text</h1>
|
21 |
| -//! <p> |
22 |
| -//! <strong>Solid</strong> |
23 |
| -//! </p> |
24 |
| -//! <p class="footer">Foot notes</p> |
25 | 16 | //! </body>
|
26 | 17 | //! </html>
|
27 | 18 | //! ```
|
|
30 | 21 | //!
|
31 | 22 | //! ```html
|
32 | 23 | //! <html>
|
33 |
| -//! <head> |
34 |
| -//! <title>Test</title> |
35 |
| -//! </head> |
| 24 | +//! <head><title>Test</title></head> |
36 | 25 | //! <body>
|
37 | 26 | //! <h1 style="color:blue;">Big Text</h1>
|
38 |
| -//! <p style="font-size:2px;"> |
39 |
| -//! <strong style="text-decoration:none;">Solid</strong> |
40 |
| -//! </p> |
41 |
| -//! <p style="font-size:1px;">Foot notes</p> |
42 | 27 | //! </body>
|
43 | 28 | //! </html>
|
44 | 29 | //! ```
|
45 | 30 | //!
|
46 |
| -//! ## Example: |
| 31 | +//! ## Usage |
47 | 32 | //!
|
48 | 33 | //! ```rust
|
49 | 34 | //! const HTML: &str = r#"<html>
|
50 | 35 | //! <head>
|
51 | 36 | //! <title>Test</title>
|
52 |
| -//! <style> |
53 |
| -//! h1, h2 { color:blue; } |
54 |
| -//! strong { text-decoration:none } |
55 |
| -//! p { font-size:2px } |
56 |
| -//! p.footer { font-size: 1px} |
57 |
| -//! </style> |
| 37 | +//! <style>h1 { color:blue; }</style> |
58 | 38 | //! </head>
|
59 | 39 | //! <body>
|
60 | 40 | //! <h1>Big Text</h1>
|
61 |
| -//! <p> |
62 |
| -//! <strong>Solid</strong> |
63 |
| -//! </p> |
64 |
| -//! <p class="footer">Foot notes</p> |
65 | 41 | //! </body>
|
66 | 42 | //! </html>"#;
|
67 | 43 | //!
|
|
72 | 48 | //! }
|
73 | 49 | //! ```
|
74 | 50 | //!
|
75 |
| -//! Or if you need more control over inlining you could use `CSSInliner`: |
| 51 | +//! ### Features |
| 52 | +//! |
| 53 | +//! `css-inline` does minimum work by default: |
| 54 | +//! |
| 55 | +//! - No CSS transformation; |
| 56 | +//! - No "style" or "link" tags removal; |
| 57 | +//! |
| 58 | +//! It also loads external stylesheets via network or filesystem, but this behavior is configurable. |
| 59 | +//! |
| 60 | +//! ### Configuration |
| 61 | +//! |
| 62 | +//! `css-inline` can be configured by using `InlineOptions` and `CSSInliner`: |
76 | 63 | //!
|
77 | 64 | //! ```rust
|
78 |
| -//! const HTML: &str = r#"<html> |
79 |
| -//! <head> |
80 |
| -//! <title>Test</title> |
81 |
| -//! <style> |
82 |
| -//! h1, h2 { color:blue; } |
83 |
| -//! strong { text-decoration:none } |
84 |
| -//! p { font-size:2px } |
85 |
| -//! p.footer { font-size: 1px} |
86 |
| -//! </style> |
87 |
| -//! </head> |
88 |
| -//! <body> |
89 |
| -//! <h1>Big Text</h1> |
90 |
| -//! <p> |
91 |
| -//! <strong>Solid</strong> |
92 |
| -//! </p> |
93 |
| -//! <p class="footer">Foot notes</p> |
94 |
| -//! </body> |
95 |
| -//! </html>"#; |
| 65 | +//! use css_inline; |
96 | 66 | //!
|
97 |
| -//!fn main() -> Result<(), css_inline::InlineError> { |
98 |
| -//! let inliner = css_inline::CSSInliner::compact(); |
99 |
| -//! let inlined = inliner.inline(HTML)?; |
100 |
| -//! // Do something with inlined HTML, e.g. send an email |
101 |
| -//! Ok(()) |
| 67 | +//! fn main() -> Result<(), css_inline::InlineError> { |
| 68 | +//! let options = css_inline::InlineOptions { |
| 69 | +//! load_remote_stylesheets: false, |
| 70 | +//! ..Default::default() |
| 71 | +//! }; |
| 72 | +//! let inliner = css_inline::CSSInliner(options); |
| 73 | +//! let inlined = inliner.inline(HTML); |
| 74 | +//! // Do something with inlined HTML, e.g. send an email |
| 75 | +//! Ok(()) |
102 | 76 | //! }
|
103 |
| -//!``` |
| 77 | +//! ``` |
| 78 | +//! |
| 79 | +//! - `remove_style_tags`. Remove "style" tags after inlining. |
| 80 | +//! - `base_url`. Base URL to resolve relative URLs |
| 81 | +//! - `load_remote_stylesheets`. Whether remote stylesheets should be loaded or not |
| 82 | +//! |
104 | 83 | #![warn(
|
105 | 84 | clippy::doc_markdown,
|
106 | 85 | clippy::redundant_closure,
|
|
0 commit comments