diff --git a/CHANGELOG.md b/CHANGELOG.md index cd33dd2..15d858a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.3.19 (TBA) + +* Ignore `@charset` CSS at-rule + ## v0.3.18 (2023-04-07) * Fixed bug in `Premailex.HTMLToPlainText.parse/3` with ``, ``, `` being excluded if the HTML element had any attributes diff --git a/lib/premailex/css_parser.ex b/lib/premailex/css_parser.ex index 4f381ac..1caef86 100644 --- a/lib/premailex/css_parser.ex +++ b/lib/premailex/css_parser.ex @@ -37,6 +37,7 @@ defmodule Premailex.CSSParser do )/ix @comments ~r/\/\*[\s\S]*?\*\//m @media_queries ~r/@media[^{]+{([\s\S]+?})\s*}/mi + @charset_rules ~r/^\s*@charset .*;$/mi @font_face ~r/@font-face\s*{[\s\S]+?}/mi @doc """ @@ -123,6 +124,7 @@ defmodule Premailex.CSSParser do string |> String.replace(@font_face, "") |> String.replace(@media_queries, "") + |> String.replace(@charset_rules, "") |> String.replace(@comments, "") end diff --git a/test/premailex/html_inline_styles_test.exs b/test/premailex/html_inline_styles_test.exs index d247ad0..7ffa7a5 100644 --- a/test/premailex/html_inline_styles_test.exs +++ b/test/premailex/html_inline_styles_test.exs @@ -5,6 +5,8 @@ defmodule Premailex.HTMLInlineStylesTest do alias ExUnit.CaptureLog @css_link_content """ + @charset "utf-8"; + html {color:black;} body,table,p,td,ul,ol {color:#333333; font-family:Arial, sans-serif; font-size:14px; line-height:22px;}