Skip to content

Commit 68d5be2

Browse files
authored
feat: Add keep_link_tags configuration option
* chore(wasm): Use `ParseError` from `css-inline` * feat: Add `keep_link_tags` configuration option
1 parent 2f9922a commit 68d5be2

File tree

20 files changed

+166
-80
lines changed

20 files changed

+166
-80
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- `keep_link_tags` configuration option.
8+
59
### Changed
610

711
- Replace `remove_style_tags` with `keep_style_tags`.

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Thank you for your interest in making `css-inline` better!
44
We'd love to have your contribution. We expect all contributors to
5-
abide by the [Contributor Covenant Code of Conduct], which you can find in the
5+
abide by the Contributor Covenant Code of Conduct, which you can find in the
66
[`CODE_OF_CONDUCT.md`] file in this repository.
77

88
[`CODE_OF_CONDUCT.md`]: https://github.com/Stranger6667/css-inline/blob/master/CODE_OF_CONDUCT.md
@@ -24,7 +24,7 @@ your commits before merging, depending.
2424

2525
## Feature requests and feedback
2626

27-
If you'd like to suggest a feature, feel free to `submit an issue <https://github.com/Stranger6667/css-inline/issues>`_
27+
If you'd like to suggest a feature, feel free to [submit an issue](https://github.com/Stranger6667/css-inline/issues)
2828
and:
2929

3030
* Write a simple and descriptive title to identify your suggestion.
@@ -34,7 +34,7 @@ and:
3434

3535
## Report bugs
3636

37-
Report bugs for `css-inline` in the `issue tracker <https://github.com/Stranger6667/css-inline/issues>`_.
37+
Report bugs for `css-inline` in the [issue tracker](https://github.com/Stranger6667/css-inline/issues).
3838

3939
If you are reporting a bug, please:
4040

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn main() -> Result<(), css_inline::InlineError> {
8686
```
8787

8888
- `keep_style_tags`. Specifies whether to keep "style" tags after inlining. Default: `false`
89+
- `keep_link_tags`. Specifies whether to keep "link" tags after inlining. Default: `false`
8990
- `base_url`. The base URL used to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `None`
9091
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `true`
9192
- `extra_css`. Extra CSS to be inlined. Default: `None`

bindings/python/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- `keep_link_tags` configuration option.
8+
59
### Changed
610

711
- Replace `remove_style_tags` with `keep_style_tags`.

bindings/python/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.9.0"
44
authors = ["Dmitry Dygalo <[email protected]>"]
55
edition = "2021"
66
rust-version = "1.60"
7+
include = ["src/lib.rs", "README.md", "CHANGELOG.md", "build.rs"]
78

89
[lib]
910
name = "css_inline"

bindings/python/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ inliner.inline("...")
106106
```
107107

108108
- `keep_style_tags`. Specifies whether to keep "style" tags after inlining. Default: `False`
109+
- `keep_link_tags`. Specifies whether to keep "link" tags after inlining. Default: `False`
109110
- `base_url`. The base URL used to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `None`
110111
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `True`
111112
- `extra_css`. Extra CSS to be inlined. Default: `None`
@@ -197,7 +198,7 @@ Realistic email 2:
197198
- `pynliner 0.8.0` - `Error: No match was found`
198199

199200
You can take a look at the benchmarks' code at `benches/bench.py` file.
200-
The results above were measured with stable `rustc 1.69.0`, `Python 3.11.0`, `Linux x86_64` on i8700K, and 32GB RAM.
201+
The results above were measured with stable `rustc 1.70.0`, `Python 3.11.0` on `Linux x86_64`.
201202

202203
## Comparison with other libraries
203204

bindings/python/css_inline.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class CSSInliner:
22
def __init__(
33
self,
44
keep_style_tags: bool = False,
5+
keep_link_tags: bool = False,
56
base_url: str | None = None,
67
load_remote_stylesheets: bool = True,
78
extra_css: str | None = None,
@@ -13,6 +14,7 @@ class CSSInliner:
1314
def inline(
1415
html: str,
1516
keep_style_tags: bool = False,
17+
keep_link_tags: bool = False,
1618
base_url: str | None = None,
1719
load_remote_stylesheets: bool = True,
1820
extra_css: str | None = None,
@@ -22,6 +24,7 @@ def inline(
2224
def inline_many(
2325
html: list[str],
2426
keep_style_tags: bool = False,
27+
keep_link_tags: bool = False,
2528
base_url: str | None = None,
2629
load_remote_stylesheets: bool = True,
2730
extra_css: str | None = None,

bindings/python/src/lib.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn parse_url(url: Option<String>) -> PyResult<Option<url::Url>> {
6767
})
6868
}
6969

70-
/// CSSInliner(keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=0)
70+
/// CSSInliner(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
7171
///
7272
/// Customizable CSS inliner.
7373
#[pyclass]
@@ -78,22 +78,23 @@ struct CSSInliner {
7878
#[pymethods]
7979
impl CSSInliner {
8080
#[new(
81-
text_signature = "(keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=0)"
81+
text_signature = "(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
8282
)]
8383
fn new(
8484
keep_style_tags: Option<bool>,
85+
keep_link_tags: Option<bool>,
8586
base_url: Option<String>,
8687
load_remote_stylesheets: Option<bool>,
8788
extra_css: Option<String>,
8889
preallocate_node_capacity: Option<usize>,
8990
) -> PyResult<Self> {
9091
let options = rust_inline::InlineOptions {
9192
keep_style_tags: keep_style_tags.unwrap_or(false),
93+
keep_link_tags: keep_link_tags.unwrap_or(false),
9294
base_url: parse_url(base_url)?,
9395
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
9496
extra_css: extra_css.map(Cow::Owned),
95-
preallocate_node_capacity: preallocate_node_capacity
96-
.unwrap_or(rust_inline::DEFAULT_HTML_TREE_CAPACITY),
97+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
9798
};
9899
Ok(CSSInliner {
99100
inner: rust_inline::CSSInliner::new(options),
@@ -117,55 +118,57 @@ impl CSSInliner {
117118
}
118119
}
119120

120-
/// inline(html, keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None)
121+
/// inline(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
121122
///
122123
/// Inline CSS in the given HTML document
123124
#[pyfunction]
124125
#[pyo3(
125-
text_signature = "(html, keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None)"
126+
text_signature = "(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
126127
)]
127128
fn inline(
128129
html: &str,
129130
keep_style_tags: Option<bool>,
131+
keep_link_tags: Option<bool>,
130132
base_url: Option<String>,
131133
load_remote_stylesheets: Option<bool>,
132134
extra_css: Option<&str>,
133135
preallocate_node_capacity: Option<usize>,
134136
) -> PyResult<String> {
135137
let options = rust_inline::InlineOptions {
136138
keep_style_tags: keep_style_tags.unwrap_or(false),
139+
keep_link_tags: keep_link_tags.unwrap_or(false),
137140
base_url: parse_url(base_url)?,
138141
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
139142
extra_css: extra_css.map(Cow::Borrowed),
140-
preallocate_node_capacity: preallocate_node_capacity
141-
.unwrap_or(rust_inline::DEFAULT_HTML_TREE_CAPACITY),
143+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
142144
};
143145
let inliner = rust_inline::CSSInliner::new(options);
144146
Ok(inliner.inline(html).map_err(InlineErrorWrapper)?)
145147
}
146148

147-
/// inline_many(htmls, keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None)
149+
/// inline_many(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
148150
///
149151
/// Inline CSS in multiple HTML documents
150152
#[pyfunction]
151153
#[pyo3(
152-
text_signature = "(htmls, keep_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None)"
154+
text_signature = "(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
153155
)]
154156
fn inline_many(
155157
htmls: &PyList,
156158
keep_style_tags: Option<bool>,
159+
keep_link_tags: Option<bool>,
157160
base_url: Option<String>,
158161
load_remote_stylesheets: Option<bool>,
159162
extra_css: Option<&str>,
160163
preallocate_node_capacity: Option<usize>,
161164
) -> PyResult<Vec<String>> {
162165
let options = rust_inline::InlineOptions {
163166
keep_style_tags: keep_style_tags.unwrap_or(false),
167+
keep_link_tags: keep_link_tags.unwrap_or(false),
164168
base_url: parse_url(base_url)?,
165169
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
166170
extra_css: extra_css.map(Cow::Borrowed),
167-
preallocate_node_capacity: preallocate_node_capacity
168-
.unwrap_or(rust_inline::DEFAULT_HTML_TREE_CAPACITY),
171+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
169172
};
170173
let inliner = rust_inline::CSSInliner::new(options);
171174
inline_many_impl(&inliner, htmls)

bindings/wasm/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- `keep_link_tags` configuration option.
8+
59
### Changed
610

711
- Replace `remove_style_tags` with `keep_style_tags`.

bindings/wasm/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ keywords = ["html", "css", "css-inline"]
1010
categories = ["web-programming"]
1111
license = "MIT"
1212
rust-version = "1.60"
13+
include = ["src/lib.rs", "LICENSE", "README.md", "CHANGELOG.md"]
1314

1415
[lib]
1516
name = "css_inline"
1617
crate-type = ["cdylib"]
1718

1819
[dependencies]
19-
serde = { version = "1.0.145", features = ["derive"], default-features = false }
20-
serde_json = "1.0.85"
21-
url = "2.3.1"
22-
wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] }
20+
serde = { version = "1", features = ["derive"], default-features = false }
21+
serde-wasm-bindgen = "0.5"
22+
serde_json = "1"
23+
wasm-bindgen = { version = "0.2" }
2324

2425
[dependencies.css-inline]
2526
path = "../../css-inline"

0 commit comments

Comments
 (0)