shithub: mycel

Download patch

ref: b290f900dc270be50ab60a43419df1b72a85ee83
parent: ca48e9e5646b85bad81bfa9706a7cc221996f9f4
author: Philip Silva <[email protected]>
date: Wed Jan 20 19:29:12 EST 2021

test for bgcolor

--- a/style/experimental_test.go
+++ b/style/experimental_test.go
@@ -1,6 +1,7 @@
 package style
 
 import (
+	"9fans.net/go/draw"
 	"github.com/chris-ramon/douceur/css"
 	"testing"
 )
@@ -18,6 +19,29 @@
 		}
 		if imgUrl != url {
 			t.Fatalf("expected %+v but got %+v", url, imgUrl)
+		}
+	}
+}
+
+func TestBackgroundColor(t *testing.T) {
+	colors := map[string]draw.Color{
+		"#000000": draw.Black,
+		"#ffffff": draw.White,
+	}
+
+	for _, k := range []string{"background", "background-color"} {
+		m := Map{
+			Declarations: make(map[string]css.Declaration),
+		}
+		for hex, d := range colors {
+			m.Declarations[k] = css.Declaration{
+				Property: k,
+				Value:    hex,
+			}
+
+			if b := m.backgroundColor(); b != d {
+				t.Fatalf("%v", b)
+			}
 		}
 	}
 }
--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -4,13 +4,11 @@
 	"9fans.net/go/draw"
 	"fmt"
 	"github.com/chris-ramon/douceur/css"
-	"github.com/chris-ramon/douceur/inliner"
 	"github.com/chris-ramon/douceur/parser"
 	cssSel "github.com/psilva261/css"
 	"github.com/mjl-/duit"
 	"golang.org/x/image/colornames"
 	"golang.org/x/net/html"
-	"io/ioutil"
 	"github.com/psilva261/opossum/logger"
 	"os/exec"
 	"regexp"
@@ -198,36 +196,6 @@
 		}
 	}
 	return
-}
-
-func Inline(html string, csss ...string) (string, error) {
-	revertCSS, err := ioutil.ReadFile("normalize.css")
-	if err != nil {
-		return "", fmt.Errorf("revert ffox css: %w", err)
-	}
-	csss = append([]string{string(revertCSS), AddOnCSS}, csss...)
-	style := "<style>" + strings.Join(csss, "\n\n") + "</style>"
-
-	var replaced string
-	if strings.Contains(html, "</head>") {
-		replaced = strings.Replace(html, "</head>", style+"\n</head>", 1)
-	} else if strings.Contains(html, "<body") {
-		replaced = strings.Replace(html, "<body", style+"\n<body", 1)
-	} else {
-		replaced = style + html
-	}
-
-	if replaced == html {
-		panic("woot")
-	}
-
-	inlined, err := inliner.Inline(replaced)
-	if err == nil {
-		html = inlined
-	} else {
-		err = fmt.Errorf("inling failed: %w", err)
-	}
-	return html, err
 }
 
 type Map struct {