diff --git a/premailer/premailer_from_bytes.go b/premailer/premailer_from_bytes.go new file mode 100644 index 0000000..e1ec907 --- /dev/null +++ b/premailer/premailer_from_bytes.go @@ -0,0 +1,19 @@ +package premailer + +import ( + "bytes" + + "github.com/PuerkitoBio/goquery" +) + +// NewPremailerFromBytes take in a document in byte +// and create a goquery.Document +// and then create and Premailer instance. +func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error) { + read := bytes.NewReader(doc) + d, err := goquery.NewDocumentFromReader(read) + if err != nil { + return nil, err + } + return NewPremailer(d, options), nil +} diff --git a/premailer/premailer_from_bytes_test.go b/premailer/premailer_from_bytes_test.go new file mode 100644 index 0000000..e0af413 --- /dev/null +++ b/premailer/premailer_from_bytes_test.go @@ -0,0 +1,51 @@ +package premailer + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPremailerBasicHTMLBytes(t *testing.T) { + html := []byte(` +
+Yes!
+Yes!
") + assert.Contains(t, result_html, "