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 =~ "