GitHub - aymerick/douceur: A simple CSS parser and inliner in Go (original) (raw)

douceur Build Status

A simple CSS parser and inliner in Golang.

Douceur Logo

Parser is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser.

Inliner only parses CSS defined in HTML document, it DOES NOT fetch external stylesheets (for now).

Inliner inserts additional attributes when possible, for example:

Inline me !

`

Becomes:

Inline me !

`

The bgcolor attribute is inserted, in addition to the inlined background-color style.

Tool usage

Install tool:

$ go install github.com/aymerick/douceur

Parse a CSS file and display result:

$ douceur parse inputfile.css

Inline CSS in an HTML document and display result:

$ douceur inline inputfile.html

Library usage

Fetch package:

$ go get github.com/aymerick/douceur

Parse CSS

package main

import ( "fmt"

"github.com/aymerick/douceur/parser"

)

func main() { input := `body { /* D4rK s1T3 */ background-color: black; }

p { /* Try to read that ! HAHA! / color: red; / L O L */ } `

stylesheet, err := parser.Parse(input)
if err != nil {
    panic("Please fill a bug :)")
}

fmt.Print(stylesheet.String())

}

Displays:

body { background-color: black; } p { color: red; }

Inline HTML

package main

import ( "fmt"

"github.com/aymerick/douceur/inliner"

)

func main() { input := `

Inline me please!

`
html, err := inliner.Inline(input)
if err != nil {
    panic("Please fill a bug :)")
}

fmt.Print(html)

}

Displays:

Inline me please!

Test

Dependencies

Similar projects