shithub: mycel

Download patch

ref: 9ea2a17822bdb50432247821c07d55e596a5fc70
parent: 79b172e05f9ee084714963a6718759dcff0f2c14
author: Philip Silva <philip.silva@protonmail.com>
date: Thu Mar 18 19:02:00 EDT 2021

Make text nodes inherit parent style

- also fix test by adding missing ;

--- a/nodes/nodes.go
+++ b/nodes/nodes.go
@@ -61,9 +61,6 @@
 	n.Wrappable = doc.Type == html.TextNode || doc.Data == "span" // TODO: probably this list needs to be extended
 	if doc.Type == html.TextNode {
 		n.Text = filterText(doc.Data)
-		n.Map = style.Map{
-			Declarations: make(map[string]css.Declaration),
-		}
 		n.Map.Declarations["display"] = css.Declaration{
 			Property: "display",
 			Value: "inline",
--- a/nodes/nodes_test.go
+++ b/nodes/nodes_test.go
@@ -51,7 +51,7 @@
 func TestNewNodeTree(t *testing.T) {
 	buf := strings.NewReader(`
 	<html>
-		<body style="width: 900px; height: 700px; font-size: 12px">
+		<body style="width: 900px; height: 700px; font-size: 12px;">
 			<p>
 				<b style="height: 100px;">bold stuff</b>
 			</p>
@@ -64,7 +64,7 @@
 	bodyW := body.Map.Css("width")
 	bodyH := body.Map.Css("height")
 	bodyF := body.Map.Css("font-size")
-	if bodyW != "900px" || bodyH != "700px"/* || bodyF != "12px"*/  {
+	if bodyW != "900px" || bodyH != "700px" || bodyF != "12px"  {
 		t.Fatalf("<%v> w=%v h=%v f=%v", body.Data(), bodyW, bodyH, bodyF)
 	}
 	b := n.Find("b")
@@ -73,5 +73,10 @@
 	bF := b.Map.Css("font-size")
 	if bW != "" || bH != "100px"/* || bF != "12px"*/  {
 		t.Fatalf("<%v> w=%v h=%v f=%v", b.Data(), bW, bH, bF)
+	}
+	text := b.Children[0]
+	textF := text.Map.Css("font-size")
+	if textF != "12px" || text.Text != "bold stuff" {
+		t.Fatalf("%+v", text)
 	}
 }