inliner: insert raw CSS rules
3 files changed
tree: 3d7b543eb8e590fabf196860701dfc1e6047a6a9
  1. css/
  2. inliner/
  3. parser/
  4. .gitignore
  5. douceur.go
  6. LICENSE
  7. README.md
README.md

douceur

A simple CSS parser and inliner in Go.

Parser uses Gorilla CSS3 tokenizer. It is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser.

Inliner uses goquery to parse HTML.

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("OMG ! SO BUGGY !")
    }

    fmt.Print(stylesheet.String())
}

Displays:

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

Inline HTML

@todo !!!

Test

go test ./... -v