From a2229a66f57bc89114df5882f95dc9a1ab2287ab Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Sun, 19 Nov 2023 17:07:12 -0500 Subject: [PATCH 1/3] Add demonstration of breakage on @charset --- test/premailex/html_inline_styles_test.exs | 2 ++ 1 file changed, 2 insertions(+) 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;} From 3a73ed15adc4156d6daaaec2fa8b08c23ac0cd81 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Sun, 19 Nov 2023 17:39:17 -0500 Subject: [PATCH 2/3] Add stripping of @charset lines --- lib/premailex/css_parser.ex | 2 ++ 1 file changed, 2 insertions(+) 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 From e01dbcb73401bd7977880ca6e40e8a0052ce5f60 Mon Sep 17 00:00:00 2001 From: Dan Schultzer <1254724+danschultzer@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:35:51 -0800 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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