Skip to content

Commit

Permalink
Merge pull request #18 from nikolagava/fix-escaped-css-rules
Browse files Browse the repository at this point in the history
Fix for escaped leftover css rules
  • Loading branch information
vanng822 authored Apr 20, 2023
2 parents 07efe00 + 08b2b65 commit f1b06eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
20 changes: 20 additions & 0 deletions premailer/data/leftover_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>

<head>
<style>
div {
background-color: red;
padding: 10px;
}

.a:hover {
background-color: green;
}
</style>
</head>

<body>
<div class="a">Hover me!</div>
</body>

</html>
10 changes: 10 additions & 0 deletions premailer/premailer_from_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ func TestBasicHTMLFromFile(t *testing.T) {
assert.Contains(t, resultHTML, "<div style=\"background-color:green\">Green color</div>")
}

func TestLeftoverCssRules(t *testing.T) {
p, err := NewPremailerFromFile("data/leftover_test.html", nil)
assert.Nil(t, err)
resultHTML, err := p.Transform()
assert.Nil(t, err)

assert.Contains(t, resultHTML, "<div class=\"a\" style=\"background-color:red;padding:10px\">Hover me!</div>")
assert.Contains(t, resultHTML, "<style type=\"text/css\">.a:hover {\nbackground-color: green !important\n}</style>")
}

func TestFromFileNotFound(t *testing.T) {
p, err := NewPremailerFromFile("data/blablabla.html", nil)
assert.NotNil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion premailer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func copyRule(selector string, rule *css.CSSRule) *css.CSSRule {
for _, s := range rule.Style.Styles {
styles = append(styles, css.NewCSSStyleDeclaration(s.Property, s.Value.Text(), s.Important))
}
copiedStyle := css.CSSStyleRule{Selector: css.NewCSSValueString(selector), Styles: styles}
copiedStyle := css.CSSStyleRule{Selector: css.NewCSSValue(selector), Styles: styles}
copiedRule := &css.CSSRule{Type: rule.Type, Style: copiedStyle}
return copiedRule
}
Expand Down

0 comments on commit f1b06eb

Please sign in to comment.