From 4c8860d60be2cc722eb3d7f8a9b9109586a650c0 Mon Sep 17 00:00:00 2001 From: Jared Dellitt Date: Wed, 28 Jan 2026 18:40:11 -0600 Subject: [PATCH 1/2] chore(PLA-2133): expose css-inline options --- lib/css_inline.ex | 67 +++++++++++++++-- lib/css_inline/native.ex | 2 +- native/css_inline_nif/Cargo.lock | 39 +++------- native/css_inline_nif/Cargo.toml | 2 +- native/css_inline_nif/src/lib.rs | 23 +++++- test/css_inline_test.exs | 125 ++++++++++++++++++++++++++++++- 6 files changed, 218 insertions(+), 40 deletions(-) diff --git a/lib/css_inline.ex b/lib/css_inline.ex index 4202f90..69aecef 100644 --- a/lib/css_inline.ex +++ b/lib/css_inline.ex @@ -21,6 +21,17 @@ defmodule CSSInline do iex> result =~ "color" true + ## Options + + The following options can be passed to `inline/2` and `inline!/2`: + + * `:inline_style_tags` - Whether to inline CSS from ` + +

Hello

+ + """ + + assert {:ok, result} = CSSInline.inline(html, keep_style_tags: true) + assert result =~ " + +

Hello

+ + """ + + assert {:ok, result} = CSSInline.inline(html, keep_style_tags: false) + refute result =~ " + +

Hello

+ + """ + + assert {:ok, result} = CSSInline.inline(html, inline_style_tags: false) + # The style should NOT be inlined + refute result =~ ~r/]*style=/ + end + + test "minify_css: false preserves whitespace in CSS" do + html = """ + + + + +

Hello

+ + """ + + assert {:ok, result} = CSSInline.inline(html, minify_css: false) + # With minify_css: false, there should be spaces around colons + assert result =~ "color: red" + end + + test "keep_link_tags: true preserves link tags" do + html = """ + + + + + +

Hello

+ + """ + + assert {:ok, result} = + CSSInline.inline(html, keep_link_tags: true, load_remote_stylesheets: false) + + assert result =~ " + + + + +

Hello

+ + """ + + # With load_remote_stylesheets: false, this should succeed without trying to fetch + assert {:ok, result} = CSSInline.inline(html, load_remote_stylesheets: false) + assert result =~ ~r/]*style="[^"]*color: ?red/ + end + + test "multiple options can be combined" do + html = """ + + + + +

Hello

+ + """ + + assert {:ok, result} = CSSInline.inline(html, keep_style_tags: true, minify_css: false) + assert result =~ " + +

Hello

+ + """ + + result = CSSInline.inline!(html, keep_style_tags: true) + assert result =~ "