package postcard import ( "fmt" "github.com/vanng822/go-premailer/premailer" ) // inlineCSS copies the rules of html's style elements onto the elements they // match, as WinterCMS does with CssToInlineStyles, so that mail clients that // drop the style block still show the design. Rules that cannot be inlined, // such as media queries and pseudo-classes, are kept in a style element. // Classes are kept, and CSS widths and heights are mirrored to the width // and height attributes (go-premailer's default options). A panic in the // inliner is returned as an error. func inlineCSS(html string) (out string, err error) { defer func() { if r := recover(); r != nil { out, err = "", fmt.Errorf("postcard: inline CSS: %v", r) } }() p, err := premailer.NewPremailerFromString(html, premailer.NewOptions()) if err != nil { return "", fmt.Errorf("postcard: inline CSS: %w", err) } out, err = p.Transform() if err != nil { return "", fmt.Errorf("postcard: inline CSS: %w", err) } return out, nil }