Skip to content

Commit

Permalink
Only add width/height attribute if in px
Browse files Browse the repository at this point in the history
  • Loading branch information
vanng822 committed Apr 27, 2019
1 parent 0a8180e commit 2506243
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions premailer/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (er *elementRules) inline() {
v := styles[p]
final = append(final, fmt.Sprintf("%s:%s", p, v))
if er.cssToAttributes {
er.style_to_basic_html_attribute(p, v)
er.styleToBasicHtmlAttribute(p, v)
}
}

Expand All @@ -73,7 +73,7 @@ func (er *elementRules) inline() {

}

func (er *elementRules) style_to_basic_html_attribute(prop, value string) {
func (er *elementRules) styleToBasicHtmlAttribute(prop, value string) {
switch prop {
case "text-align":
er.element.SetAttr("align", value)
Expand All @@ -86,7 +86,7 @@ func (er *elementRules) style_to_basic_html_attribute(prop, value string) {
case "height":
if strings.HasSuffix(value, "px") {
value = value[:len(value)-2]
er.element.SetAttr(prop, value)
}
er.element.SetAttr(prop, value)
}
}
4 changes: 2 additions & 2 deletions premailer/premailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestWithInline(t *testing.T) {
</style>
</head>
<body>
<h1 style="width: 100%;">Hi!</h1>
<h1 style="width: 100px;">Hi!</h1>
<p><strong>Yes!</strong></p>
</body>
</html>`
Expand All @@ -103,7 +103,7 @@ func TestWithInline(t *testing.T) {
result_html, err := p.Transform()
assert.Nil(t, err)

assert.Contains(t, result_html, "<h1 style=\"color:red;width:100%\" width=\"100%\">Hi!</h1>")
assert.Contains(t, result_html, "<h1 style=\"color:red;width:100px\" width=\"100\">Hi!</h1>")
assert.Contains(t, result_html, "<p><strong style=\"text-decoration:none\">Yes!</strong></p>")
assert.NotContains(t, result_html, "<style type=\"text/css\">")
}
Expand Down

0 comments on commit 2506243

Please sign in to comment.