Skip to content

Commit

Permalink
Merge pull request #83 from backspace/charset-breaks
Browse files Browse the repository at this point in the history
Add stripping of @charset lines
  • Loading branch information
danschultzer authored Nov 19, 2023
2 parents de3d368 + e01dbcb commit 8a21ed9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 `<thread>`, `<tbody>`, `<tfoot>` being excluded if the HTML element had any attributes
Expand Down
2 changes: 2 additions & 0 deletions lib/premailex/css_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/premailex/html_inline_styles_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down

0 comments on commit 8a21ed9

Please sign in to comment.