Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/css_inline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ defmodule CSSInline do
* `:load_remote_stylesheets` - Whether to load remote stylesheets referenced in `<link>` tags.
Defaults to `true`. Set to `false` to skip external stylesheets.
* `:minify_css` - Whether to minify the inlined CSS. Defaults to `true`.
* `:check_depth` - Whether to check HTML nesting depth before inlining. Defaults to `true`.
* `:max_depth` - Maximum allowed HTML nesting depth. Documents exceeding this return
`{:error, :nesting_depth_exceeded}`. Only applies when `:check_depth` is `true`. Defaults to `128`.

## Performance

Expand All @@ -47,14 +50,18 @@ defmodule CSSInline do
keep_style_tags: false,
keep_link_tags: false,
load_remote_stylesheets: true,
minify_css: true
minify_css: true,
check_depth: true,
max_depth: 128

@type t :: %__MODULE__{
inline_style_tags: boolean(),
keep_style_tags: boolean(),
keep_link_tags: boolean(),
load_remote_stylesheets: boolean(),
minify_css: boolean()
minify_css: boolean(),
check_depth: boolean(),
max_depth: pos_integer()
}
end

Expand All @@ -64,6 +71,8 @@ defmodule CSSInline do
| {:keep_link_tags, boolean()}
| {:load_remote_stylesheets, boolean()}
| {:minify_css, boolean()}
| {:check_depth, boolean()}
| {:max_depth, pos_integer()}

@doc """
Inlines CSS from `<style>` tags into element `style` attributes.
Expand All @@ -77,6 +86,8 @@ defmodule CSSInline do
* `:keep_link_tags` - Whether to keep `<link>` tags after processing. Defaults to `false`.
* `:load_remote_stylesheets` - Whether to load remote stylesheets. Defaults to `true`.
* `:minify_css` - Whether to minify the inlined CSS. Defaults to `true`.
* `:check_depth` - Whether to check HTML nesting depth before inlining. Defaults to `true`.
* `:max_depth` - Maximum allowed HTML nesting depth. Defaults to `128`.
"""
@spec inline(String.t(), [option()]) :: {:ok, String.t()} | {:error, term()}
def inline(html, opts \\ []) when is_binary(html) and is_list(opts) do
Expand Down Expand Up @@ -105,6 +116,8 @@ defmodule CSSInline do
* `:keep_link_tags` - Whether to keep `<link>` tags after processing. Defaults to `false`.
* `:load_remote_stylesheets` - Whether to load remote stylesheets. Defaults to `true`.
* `:minify_css` - Whether to minify the inlined CSS. Defaults to `true`.
* `:check_depth` - Whether to check HTML nesting depth before inlining. Defaults to `true`.
* `:max_depth` - Maximum allowed HTML nesting depth. Defaults to `128`.
"""
@spec inline!(String.t(), [option()]) :: String.t()
def inline!(html, opts \\ []) when is_binary(html) and is_list(opts) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CSSInline.MixProject do
use Mix.Project

@version "0.1.2"
@version "0.2.0"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.3", "4252d5d4098da7415c390e847c814bad3764c94a814a0b4245176215615e1035", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "953297c02582a33411ac6208f2c6e55f0e870df7f80da724ed613f10e6706afd"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
"rustler": {:hex, :rustler, "0.37.1", "721434020c7f6f8e1cdc57f44f75c490435b01de96384f8ccb96043f12e8a7e0", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "24547e9b8640cf00e6a2071acb710f3e12ce0346692e45098d84d45cdb54fd79"},
"rustler": {:hex, :rustler, "0.37.3", "5f4e6634d43b26f0a69834dd1d3ed4e1710b022a053bf4a670220c9540c92602", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "a6872c6f53dcf00486d1e7f9e046e20e01bf1654bdacc4193016c2e8002b32a2"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.8.4", "700a878312acfac79fb6c572bb8b57f5aae05fe1cf70d34b5974850bbf2c05bf", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "3b33d99b540b15f142ba47944f7a163a25069f6d608783c321029bc1ffb09514"},
}
Loading
Loading