Skip to content

Commit 4deb099

Browse files
authored
chore: Various updates
1 parent 52270ba commit 4deb099

36 files changed

+467
-382
lines changed

.github/workflows/build.yml

+25-22
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
name: Generic pre-commit checks
2323
runs-on: ubuntu-20.04
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v3
2626
with:
2727
fetch-depth: 1
2828

29-
- uses: actions/setup-python@v2
29+
- uses: actions/setup-python@v4
3030
with:
3131
python-version: 3.9
3232

@@ -37,11 +37,11 @@ jobs:
3737
name: Test (stable)
3838
runs-on: ubuntu-20.04
3939
steps:
40-
- uses: actions/checkout@v2
40+
- uses: actions/checkout@v3
4141
with:
4242
submodules: true
4343

44-
- uses: actions/setup-python@v2
44+
- uses: actions/setup-python@v4
4545
with:
4646
python-version: 3.7
4747

@@ -62,7 +62,7 @@ jobs:
6262
name: Rustfmt
6363
runs-on: ubuntu-20.04
6464
steps:
65-
- uses: actions/checkout@v2
65+
- uses: actions/checkout@v3
6666
- uses: actions-rs/toolchain@v1
6767
with:
6868
profile: minimal
@@ -76,7 +76,7 @@ jobs:
7676
name: Clippy
7777
runs-on: ubuntu-20.04
7878
steps:
79-
- uses: actions/checkout@v2
79+
- uses: actions/checkout@v3
8080
- uses: actions-rs/toolchain@v1
8181
with:
8282
profile: minimal
@@ -90,7 +90,7 @@ jobs:
9090
name: MSRV
9191
runs-on: ubuntu-20.04
9292
steps:
93-
- uses: actions/checkout@v2
93+
- uses: actions/checkout@v3
9494
- uses: actions-rs/toolchain@v1
9595
with:
9696
profile: minimal
@@ -109,10 +109,10 @@ jobs:
109109
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
110110
runs-on: ${{ matrix.os }}
111111
steps:
112-
- uses: actions/checkout@v2
112+
- uses: actions/checkout@v3
113113
with:
114114
submodules: true
115-
- uses: actions/setup-python@v2
115+
- uses: actions/setup-python@v4
116116
with:
117117
python-version: ${{ matrix.python-version }}
118118
architecture: x64
@@ -133,7 +133,7 @@ jobs:
133133
name: Tests for WASM crate
134134
runs-on: ubuntu-20.04
135135
steps:
136-
- uses: actions/checkout@v2
136+
- uses: actions/checkout@v3
137137
with:
138138
submodules: true
139139
- uses: actions-rs/toolchain@v1
@@ -154,7 +154,7 @@ jobs:
154154
name: TypeScript tests for WASM crate
155155
runs-on: ubuntu-20.04
156156
steps:
157-
- uses: actions/checkout@v2
157+
- uses: actions/checkout@v3
158158
with:
159159
submodules: true
160160
- uses: actions-rs/toolchain@v1
@@ -181,7 +181,7 @@ jobs:
181181
name: Check features
182182
runs-on: ubuntu-20.04
183183
steps:
184-
- uses: actions/checkout@v2
184+
- uses: actions/checkout@v3
185185
with:
186186
submodules: true
187187
- uses: actions-rs/toolchain@v1
@@ -197,19 +197,16 @@ jobs:
197197
name: Code coverage
198198
runs-on: ubuntu-20.04
199199
steps:
200-
- uses: actions/checkout@v2
200+
- uses: actions/checkout@v3
201201
with:
202202
submodules: true
203203

204-
- name: Toolchain setup
205-
uses: actions-rs/toolchain@v1
204+
- uses: actions-rs/toolchain@v1
206205
with:
207-
toolchain: nightly
206+
profile: minimal
207+
toolchain: stable
208208
override: true
209209

210-
- name: Install `cargo-tarpaulin`
211-
run: cargo install cargo-tarpaulin
212-
213210
- name: Cache cargo
214211
uses: actions/cache@v3
215212
with:
@@ -219,7 +216,10 @@ jobs:
219216
target
220217
key: coverage-cargo-cache
221218

222-
- uses: actions/setup-python@v2
219+
- name: Install cargo-llvm-cov
220+
uses: taiki-e/install-action@cargo-llvm-cov
221+
222+
- uses: actions/setup-python@v4
223223
with:
224224
python-version: 3.7
225225

@@ -229,15 +229,18 @@ jobs:
229229
# Starts the server in background
230230
python ./css-inline/tests/server.py &
231231
232-
- name: Run tests
233-
run: cargo tarpaulin --verbose --all-features --out Xml
232+
- name: Generate code coverage
233+
run: cargo llvm-cov --all-features --lcov --output-path lcov.info
234234
working-directory: ./css-inline
235235

236236
- name: Upload coverage to Codecov
237237
uses: codecov/codecov-action@v3
238238
if: ${{ env.GITHUB_REPOSITORY }} == 'Stranger6667/css-inline'
239239
with:
240+
token: ${{ secrets.CODECOV_TOKEN }}
240241
name: coverage
242+
files: lcov.info
243+
fail_ci_if_error: true
241244

242245
fuzz:
243246
name: Fuzz

.github/workflows/rust-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
rust-release:
1010
runs-on: ubuntu-20.04
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
- uses: actions-rs/toolchain@v1
1414
with:
1515
profile: minimal

.github/workflows/wasm-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
wasm-release:
1010
runs-on: ubuntu-20.04
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
- uses: actions-rs/toolchain@v1
1414
with:
1515
profile: minimal

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: check-yaml
99
- id: end-of-file-fixer
1010
- id: trailing-whitespace
11-
exclude: ^.*\.(md|rst)$
11+
exclude: test_inlining.rs
1212
- id: mixed-line-ending
1313
args: [--fix=lf]
1414
- id: check-merge-conflict

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- Replace `remove_style_tags` with `keep_style_tags`.
8+
9+
### Removed
10+
11+
- The `inline_style_tags` configuration option.
12+
513
## [0.9.0] - 2023-06-10
614

715
### Fixed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# css-inline contribution guidelines
22

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

1010
## License
1111

12-
The code in this project is licensed under MIT license.
12+
The code in this project is licensed under MIT license.
1313
By contributing to `css-inline`, you agree that your contributions will be licensed under its MIT license.
1414

1515
## Pull Requests

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-2021 Dmitry Dygalo
3+
Copyright (c) 2020-2023 Dmitry Dygalo
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+58-34
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# css-inline
22

3-
[![ci](https://github.com/Stranger6667/css-inline/workflows/ci/badge.svg)](https://github.com/Stranger6667/css-inline/actions)
4-
[![codecov](https://codecov.io/gh/Stranger6667/css-inline/branch/master/graph/badge.svg)](https://codecov.io/gh/Stranger6667/css-inline)
5-
[![Crates.io](https://img.shields.io/crates/v/css-inline.svg)](https://crates.io/crates/css-inline)
6-
[![docs.rs](https://docs.rs/css-inline/badge.svg)](https://docs.rs/css-inline/)
7-
[![gitter](https://img.shields.io/gitter/room/Stranger6667/css-inline.svg)](https://gitter.im/Stranger6667/css-inline)
3+
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/Stranger6667/css-inline/build.yml?style=flat-square&labelColor=555555&logo=github" height="20">](https://github.com/Stranger6667/css-inline)
4+
[<img alt="crates.io" src="https://img.shields.io/crates/v/css-inline.svg?style=flat-square&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/css-inline)
5+
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-css_inline-66c2a5?style=flat-square&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/css-inline)
6+
[<img alt="codecov.io" src="https://img.shields.io/codecov/c/gh/Stranger6667/css-inline?logo=codecov&style=flat-square&token=tOzvV4kDY0" height="20">](https://app.codecov.io/github/Stranger6667/css-inline)
7+
[<img alt="gitter" src="https://img.shields.io/gitter/room/Stranger6667/css-inline?style=flat-square" height="20">](https://gitter.im/Stranger6667/css-inline)
88

9-
A crate for inlining CSS into HTML documents. It is built with Mozilla's Servo project components.
9+
`css-inline` is a crate that inlines CSS into HTML documents, built using components from Mozilla's Servo project.
1010

11-
When you send HTML emails, you need to use "style" attributes instead of "style" tags. For example, this HTML:
11+
This process is essential for sending HTML emails as you need to use "style" attributes instead of "style" tags.
12+
13+
For instance, the crate transforms HTML like this:
1214

1315
```html
1416
<html>
@@ -22,7 +24,7 @@ When you send HTML emails, you need to use "style" attributes instead of "style"
2224
</html>
2325
```
2426

25-
Will be turned into this:
27+
into:
2628

2729
```html
2830
<html>
@@ -35,13 +37,16 @@ Will be turned into this:
3537
</html>
3638
```
3739

38-
To use it in your project add the following line to your `dependencies` section in the project's `Cargo.toml` file:
40+
## Installation
41+
42+
To include it in your project, add the following line to the dependencies section in your project's `Cargo.toml` file:
3943

4044
```toml
45+
[dependencies]
4146
css-inline = "0.9"
4247
```
4348

44-
Minimum Supported Rust Version is 1.60.
49+
The Minimum Supported Rust Version is 1.60.
4550

4651
## Usage
4752

@@ -80,13 +85,13 @@ fn main() -> Result<(), css_inline::InlineError> {
8085
}
8186
```
8287

83-
- `inline_style_tags`. Whether to inline CSS from "style" tags. Default: `true`
84-
- `remove_style_tags`. Remove "style" tags after inlining. Default: `false`
85-
- `base_url`. Base URL to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `None`
86-
- `load_remote_stylesheets`. Whether remote stylesheets should be loaded or not. Default: `true`
87-
- `extra_css`. Additional CSS to inline. Default: `None`
88+
- `keep_style_tags`. Specifies whether to keep "style" tags after inlining. Default: `false`
89+
- `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`
90+
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `true`
91+
- `extra_css`. Extra CSS to be inlined. Default: `None`
92+
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `8`
8893

89-
If you'd like to skip CSS inlining for an HTML tag, add `data-css-inline="ignore"` attribute to it:
94+
You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="ignore"` attribute to it:
9095

9196
```html
9297
<head>
@@ -100,7 +105,7 @@ If you'd like to skip CSS inlining for an HTML tag, add `data-css-inline="ignore
100105
</html>
101106
```
102107

103-
This attribute also allows you to skip `link` and `style` tags:
108+
The `data-css-inline="ignore"` attribute also allows you to skip `link` and `style` tags:
104109

105110
```html
106111
<head>
@@ -114,18 +119,33 @@ This attribute also allows you to skip `link` and `style` tags:
114119
</html>
115120
```
116121

122+
If you'd like to load stylesheets from your filesystem, use the `file://` scheme:
123+
124+
```rust
125+
const HTML: &str = "...";
126+
127+
fn main() -> Result<(), css_inline::InlineError> {
128+
let base_url = css_inline::Url::parse("file://styles/email/").expect("Invalid URL");
129+
let inliner = css_inline::CSSInliner::options()
130+
.base_url(Some(base_url))
131+
.build();
132+
let inlined = inliner.inline(HTML);
133+
// Do something with inlined HTML, e.g. send an email
134+
Ok(())
135+
}
136+
```
137+
117138
## Standards support & restrictions
118139

119-
`css-inline` is built on top of [cssparser](https://crates.io/crates/cssparser) and relies on its behavior for CSS parsing.
120-
Notably:
140+
`css-inline` is built on top of [html5ever](https://crates.io/crates/html5ever) and [cssparser](https://crates.io/crates/cssparser) and relies on their behavior for HTML & CSS parsing.
121141

122-
- Only HTML 5, XHTML is not supported;
123-
- Only CSS 3;
124-
- Only UTF-8 for string representation. Other document encodings are not yet supported.
142+
- Only HTML 5 is supported, not XHTML.
143+
- Only CSS 3 is supported.
144+
- Only UTF-8 encoding for string representation. Other document encodings are not yet supported.
125145

126146
## Bindings
127147

128-
There are bindings for Python and WebAssembly in the `bindings` directory.
148+
We provide bindings for Python and WebAssembly. Check the `bindings` directory for more information.
129149

130150
## Command Line Interface
131151

@@ -148,23 +168,23 @@ ARGS:
148168
HTML tags, according to the corresponding CSS selectors.
149169
When multiple documents are specified, they will be
150170
processed in parallel, and each inlined file will be saved
151-
with "inlined." prefix. E.g., for "example.html", there
152-
will be "inlined.example.html".
171+
with an "inlined." prefix. For example, for "example.html",
172+
there will be "inlined.example.html".
153173
154174
OPTIONS:
155175
--inline-style-tags
156-
Whether to inline CSS from "style" tags. The default
157-
value is `true`. To disable inlining from "style" tags
158-
use `--inline-style-tags=false`.
176+
Specifies whether to inline CSS from "style" tags.
177+
To disable inlining from "style" tags use
178+
`--inline-style-tags=false`.
159179
160-
--remove-style-tags
161-
Remove "style" tags after inlining.
180+
--keep-style-tags
181+
Keep "style" tags after inlining.
162182
163183
--base-url
164-
Used for loading external stylesheets via relative URLs.
184+
The base URL used to resolve relative URLs.
165185
166186
--load-remote-stylesheets
167-
Whether remote stylesheets should be loaded or not.
187+
Specifies if remote stylesheets should be loaded or not.
168188
169189
--extra-css
170190
Additional CSS to inline.
@@ -175,11 +195,15 @@ OPTIONS:
175195

176196
## Extra materials
177197

178-
If you want to know how this library was created & how it works internally, you could take a look at these articles:
198+
If you're interested in learning how this library was created and how it works internally, check out these articles:
179199

180200
- [Rust crate](https://dygalo.dev/blog/rust-for-a-pythonista-2/)
181201
- [Python bindings](https://dygalo.dev/blog/rust-for-a-pythonista-3/)
182202

183203
## Support
184204

185-
If you have anything to discuss regarding this library, please, join our [gitter](https://gitter.im/Stranger6667/css-inline)!
205+
If you have any questions or discussions related to this library, please join our [gitter](https://gitter.im/Stranger6667/css-inline)!
206+
207+
## License
208+
209+
This project is licensed under the terms of the <a href="LICENSE">MIT license</a>.

0 commit comments

Comments
 (0)