Skip to content

Commit

Permalink
Fix border and outline, fixes #214
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Aug 11, 2018
1 parent fdf0cc1 commit b27457b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 23 additions & 12 deletions css/css.go
Expand Up @@ -509,20 +509,31 @@ func (c *cssMinifier) minifyProperty(prop css.Hash, values []Token) []Token {
values = values[:3]
}
}
case css.Outline, css.Border, css.Border_Bottom, css.Border_Left, css.Border_Right, css.Border_Top:
none := false
iZero := -1
for i, value := range values {
if len(value.Data) == 1 && value.Data[0] == '0' {
iZero = i
} else if css.ToHash(value.Data) == css.None {
values[i].TokenType = css.NumberToken
values[i].Data = zeroBytes
none = true
case css.Border, css.Border_Bottom, css.Border_Left, css.Border_Right, css.Border_Top:
for i := 0; i < len(values); i++ {
if values[i].TokenType == css.IdentToken {
val := css.ToHash(values[i].Data)
if val == css.None || val == css.Currentcolor || val == css.Medium {
values = append(values[:i], values[i+1:]...)
i--
}
}
}
if len(values) == 0 {
values = []Token{{css.IdentToken, []byte("none"), nil}}
}
case css.Outline:
for i := 0; i < len(values); i++ {
if values[i].TokenType == css.IdentToken {
val := css.ToHash(values[i].Data)
if val == css.None || val == css.Medium { // color=invert is not supported by all browsers
values = append(values[:i], values[i+1:]...)
i--
}
}
}
if none && iZero != -1 {
values = append(values[:iZero], values[iZero+1:]...)
if len(values) == 0 {
values = []Token{{css.IdentToken, []byte("none"), nil}}
}
case css.Background:
hasSize := false
Expand Down
9 changes: 5 additions & 4 deletions css/css_test.go
Expand Up @@ -133,12 +133,13 @@ func TestCSSInline(t *testing.T) {
{"font:normal normal bold normal medium/normal arial,sans-serif", "font:700 medium arial,sans-serif"},
{"font:400 medium/normal 'Arial'", "font:medium arial"},
{"font:medium/normal 'Arial'", "font:medium arial"},
{"outline: none;", "outline:0"},
{"outline: none;", "outline:none"},
{"outline: solid black 0;", "outline:solid #000 0"},
{"outline: none black 5px;", "outline:0 #000 5px"},
{"outline: none !important;", "outline:0!important"},
{"border-left: none;", "border-left:0"},
{"outline: none black medium;", "outline:#000"},
{"outline: none !important;", "outline:none!important"},
{"border-left: none;", "border-left:none"},
{"border-left: none 0;", "border-left:0"},
{"border-left: none medium currentcolor;", "border-left:none"},
{"border-left: 0 dashed red;", "border-left:0 dashed red"},
{"margin: 1 1 1 1;", "margin:1"},
{"margin: 1 2 1 2;", "margin:1 2"},
Expand Down

0 comments on commit b27457b

Please sign in to comment.