diff --git a/CHANGELOG.md b/CHANGELOG.md index d1a65823..dbc58065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - `media_type` option to inline rules from `@media` blocks that apply to the given media type. [#410](https://github.com/Stranger6667/css-inline/issues/410) +### Changed + +- **BREAKING**: Error on `keep_at_rules` in `inline_fragment` (`InlineError::UnsupportedFragmentOption`). [#514](https://github.com/Stranger6667/css-inline/issues/514) + ### Fixed - `extra_css`, fragment CSS and linked stylesheets not inlined when `keep_at_rules` is enabled and `inline_style_tags` is disabled. diff --git a/README.md b/README.md index 3849a7e0..ddca3703 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ fn main() -> css_inline::Result<()> { - `inline_style_tags`. Inline CSS from `style` tags. With `false`, `css-inline` ignores their CSS and still removes the tags unless `keep_style_tags` is `true`. Default: `true` - `keep_style_tags`. Keep `style` tags after inlining. Default: `false` - `keep_link_tags`. Keep `link` tags after inlining. Default: `false` -- `keep_at_rules`. Keep at-rules (starting with `@`) after inlining. Default: `false` +- `keep_at_rules`. Keep at-rules (starting with `@`) after inlining. Errors in fragment inlining. Default: `false` - `minify_css`. Remove trailing semicolons and spaces between properties and values. Default: `false` - `base_url`. Base URL for resolving relative URLs. Use the `file://` scheme to load stylesheets from the filesystem. Default: `None` - `load_remote_stylesheets`. Load stylesheets from `link` tags, over the network or from `file://` paths. Default: `true` diff --git a/crates/css-inline-c/CHANGELOG.md b/crates/css-inline-c/CHANGELOG.md index c685060f..5ab412c1 100644 --- a/crates/css-inline-c/CHANGELOG.md +++ b/crates/css-inline-c/CHANGELOG.md @@ -6,6 +6,10 @@ - `media_type` option to inline rules from `@media` blocks that apply to the given media type. [#410](https://github.com/Stranger6667/css-inline/issues/410) +### Changed + +- **BREAKING**: `CSS_RESULT_UNSUPPORTED_FRAGMENT_OPTION` error on `keep_at_rules` in `css_inline_fragment_to`. [#514](https://github.com/Stranger6667/css-inline/issues/514) + ### Fixed - `extra_css`, fragment CSS and linked stylesheets not inlined when `keep_at_rules` is enabled and `inline_style_tags` is disabled. diff --git a/crates/css-inline-c/README.md b/crates/css-inline-c/README.md index 4bb99758..c67142cf 100644 --- a/crates/css-inline-c/README.md +++ b/crates/css-inline-c/README.md @@ -201,6 +201,7 @@ Both functions return a `CssResult`. `CSS_RESULT_OK` is `0`; any other value is | `CSS_RESULT_INVALID_INPUT_STRING` | The HTML or CSS input is not UTF-8 | | `CSS_RESULT_INVALID_CACHE_SIZE` | The stylesheet cache size is `0` | | `CSS_RESULT_INVALID_MEDIA_TYPE` | `media_type` is not UTF-8 | +| `CSS_RESULT_UNSUPPORTED_FRAGMENT_OPTION` | `keep_at_rules` is set in `css_inline_fragment_to()` | ### Configuration @@ -227,7 +228,7 @@ Fields: - `inline_style_tags`. Inline CSS from `style` tags. Default: `true` - `keep_style_tags`. Keep `style` tags after inlining. Default: `false` - `keep_link_tags`. Keep `link` tags after inlining. Default: `false` -- `keep_at_rules`. Keep at-rules (starting with `@`) after inlining. Default: `false` +- `keep_at_rules`. Keep at-rules (starting with `@`) after inlining. Errors in fragment inlining. Default: `false` - `minify_css`. Remove trailing semicolons and spaces between properties and values. Default: `false` - `base_url` (`const char *`). Base URL for resolving relative URLs. Use the `file://` scheme to load stylesheets from your filesystem. Default: `NULL` - `load_remote_stylesheets`. Load stylesheets from `link` tags, over the network or from `file://` paths. Default: `true` diff --git a/crates/css-inline-c/src/lib.rs b/crates/css-inline-c/src/lib.rs index 34ea9e52..efe1e759 100644 --- a/crates/css-inline-c/src/lib.rs +++ b/crates/css-inline-c/src/lib.rs @@ -36,6 +36,8 @@ pub enum CssResult { InvalidCacheSize, /// Invalid media_type parameter. InvalidMediaType, + /// Option that is not supported for fragment inlining. + UnsupportedFragmentOption, } impl From for CssResult { @@ -45,6 +47,7 @@ impl From for CssResult { InlineError::Network { .. } => CssResult::RemoteStylesheetNotAvailable, InlineError::ParseError(_) => CssResult::InternalSelectorParseError, InlineError::MissingStyleSheet { .. } => CssResult::MissingStylesheet, + InlineError::UnsupportedFragmentOption => CssResult::UnsupportedFragmentOption, } } } diff --git a/crates/css-inline-c/tests/main.c b/crates/css-inline-c/tests/main.c index b33ef923..300290e6 100644 --- a/crates/css-inline-c/tests/main.c +++ b/crates/css-inline-c/tests/main.c @@ -133,6 +133,14 @@ static void test_inline_fragment(void) { assert(strcmp(output, SAMPLE_INLINED_FRAGMENT) == 0); } +static void test_inline_fragment_keep_at_rules(void) { + CssInlinerOptions options = css_inliner_default_options(); + options.keep_at_rules = true; + char output[MAX_SIZE]; + assert(css_inline_fragment_to(&options, SAMPLE_FRAGMENT, SAMPLE_FRAGMENT_STYLE, output, sizeof(output)) == + CSS_RESULT_UNSUPPORTED_FRAGMENT_OPTION); +} + static void test_remove_inlined_selectors(void) { char html[] = "

Test

"; CssInlinerOptions options = css_inliner_default_options(); @@ -174,6 +182,7 @@ int main(void) { test_cache_valid(); test_cache_invalid(); test_inline_fragment(); + test_inline_fragment_keep_at_rules(); test_remove_inlined_selectors(); test_resolve_css_variables(); test_media_type(); diff --git a/crates/css-inline-java/CHANGELOG.md b/crates/css-inline-java/CHANGELOG.md index 4b9ff03a..d093cec2 100644 --- a/crates/css-inline-java/CHANGELOG.md +++ b/crates/css-inline-java/CHANGELOG.md @@ -6,6 +6,10 @@ - `setMediaType` option to inline rules from `@media` blocks that apply to the given media type. [#410](https://github.com/Stranger6667/css-inline/issues/410) +### Changed + +- **BREAKING**: Error on `setKeepAtRules(true)` in `inlineFragment`. [#514](https://github.com/Stranger6667/css-inline/issues/514) + ### Fixed - `setExtraCss`, fragment CSS and linked stylesheets not inlined when `setKeepAtRules` is enabled and `setInlineStyleTags` is disabled. diff --git a/crates/css-inline-java/README.md b/crates/css-inline-java/README.md index f4628ab6..cba32353 100644 --- a/crates/css-inline-java/README.md +++ b/crates/css-inline-java/README.md @@ -169,7 +169,7 @@ public class ConfigExample { - **`setInlineStyleTags(boolean)`** - Inline CSS from `

Hi

"#, + "", + ) + .unwrap(); + assert_eq!( + inlined, + r#"

Hi

"# + ); +} + // Padding to ensure documents exceed the 1024-byte threshold for indexed lookups const PADDING: &str = " "; @@ -1997,7 +2022,6 @@ fn keep_style_tags_and_remove_inlined_selectors_with_keep_at_rules_keeps_extra_c fn remove_inlined_selectors_with_at_rules_in_fragment() { let inliner = CSSInliner::options() .remove_inlined_selectors(true) - .keep_at_rules(true) .keep_style_tags(true) .build(); let html = r#"