go-premailer: github.com/vanng822/go-premailer/premailer Index | Files

package premailer

import "github.com/vanng822/go-premailer/premailer"

Package premailer is for inline styling.

import (
	"fmt"
	"github.com/vanng822/go-premailer/premailer"
	"log"
)

func main() {
	prem, err := premailer.NewPremailerFromFile(inputFile, premailer.NewOptions())
	if err != nil {
		log.Fatal(err)
	}
	html, err := prem.Transform()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(html)
}
// Input

<html>
<head>
<title>Title</title>
<style type="text/css">
	h1 { width: 300px; color:red; }
	strong { text-decoration:none; }
</style>
</head>
<body>
	<h1>Hi!</h1>
	<p><strong>Yes!</strong></p>
</body>
</html>

// Output

<html>
<head>
<title>Title</title>
</head>
<body>
	<h1 style="color:red;width:300px" width="300">Hi!</h1>
	<p><strong style="text-decoration:none">Yes!</strong></p>
</body>
</html>

Index

Package Files

doc.go element.go options.go premailer.go premailer_from_bytes.go premailer_from_file.go premailer_from_string.go specificity.go style_rule.go util.go

type Options Uses

type Options struct {
    // Remove class attribute from element
    // Default false
    RemoveClasses bool
    // Copy related CSS properties into HTML attributes (e.g. background-color to bgcolor)
    // Default true
    CssToAttributes bool
}

Options for controlling behaviour

func NewOptions Uses

func NewOptions() *Options

NewOptions return an Options instance with default value

type Premailer Uses

type Premailer interface {
    // Transform process and inlining css
    // It start to collect the rules in the document style tags
    // Calculate specificity and sort the rules based on that
    // It then collects the affected elements
    // And applies the rules on those
    // The leftover rules will put back into a style element
    Transform() (string, error)
}

Premailer is the inteface of Premailer

func NewPremailer Uses

func NewPremailer(doc *goquery.Document, options *Options) Premailer

NewPremailer return a new instance of Premailer It take a Document as argument and it shouldn't be nil

func NewPremailerFromBytes Uses

func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error)

NewPremailerFromBytes take in a document in byte and create a goquery.Document and then create and Premailer instance.

func NewPremailerFromFile Uses

func NewPremailerFromFile(filename string, options *Options) (Premailer, error)

NewPremailerFromFile take an filename Read the content of this file and create a goquery.Document and then create and Premailer instance.

func NewPremailerFromString Uses

func NewPremailerFromString(doc string, options *Options) (Premailer, error)

NewPremailerFromString take in a document in string format and create a goquery.Document and then create and Premailer instance.

Package premailer imports 12 packages (graph) and is imported by 4 packages. Updated 2019-05-06. Refresh now. Tools for package owners.