shithub: mycel

Download patch

ref: 49e401ef4b569e9c6b305648af6f7e652d575d2f
parent: 9d68cdc7fb23d4249c24d9e0e15323386edd3366
author: Philip Silva <philip.silva@protonmail.com>
date: Mon Apr 5 06:09:15 EDT 2021

Handle inherit property correctly

--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -263,6 +263,9 @@
 	}
 	// overwrite with higher prio child props
 	for k, v := range ccs.Declarations {
+		if v.Value == "inherit" {
+			continue
+		}
 		res.Declarations[k] = v
 	}
 
--- a/style/stylesheets_test.go
+++ b/style/stylesheets_test.go
@@ -251,6 +251,28 @@
 	}
 }
 
+func TestApplyChildStyleInherit2(t *testing.T) {
+	parent := Map{
+		Declarations: make(map[string]css.Declaration),
+	}
+	child := Map{
+		Declarations: make(map[string]css.Declaration),
+	}
+	parent.Declarations["font-size"] = css.Declaration{
+		Property: "font-size",
+		Value:    "12pt",
+	}
+	child.Declarations["font-size"] = css.Declaration{
+		Property: "font-size",
+		Value:    "inherit",
+	}
+
+	res := parent.ApplyChildStyle(child, true)
+	if v := res.Declarations["font-size"].Value; v != "12pt" {
+		t.Fatalf(v)
+	}
+}
+
 func TestLength(t *testing.T) {
 	lpx := map[string]float64{
 		"auto": 0.0,