douceur
Douceur 0.2.0
Parser CSS dan Inliner sederhana di Golang.
Parser samar -samar terinspirasi oleh modul sintaks CSS Level 3 dan parser JS yang sesuai.
Inliner hanya mem -parsing CSS yang didefinisikan dalam dokumen HTML, itu tidak mengambil stylesheet eksternal (untuk saat ini).
Inliner memasukkan atribut tambahan jika memungkinkan, misalnya:
< html >
< head >
< style type =" text/css " >
body {
background-color: #f2f2f2;
}
</ style >
</ head >
< body >
< p > Inline me ! </ p >
</ body >
</ html > `
Menjadi:
< html >
< head >
</ head >
< body style =" background-color: #f2f2f2; " bgcolor =" #f2f2f2 " >
< p > Inline me ! </ p >
</ body >
</ html > `
Atribut bgcolor
dimasukkan, di samping gaya background-color
yang diatur.
Instal Tool:
$ go install github.com/aymerick/douceur
Parse file CSS dan hasil tampilan:
$ douceur parse inputfile.css
Inline CSS dalam dokumen HTML dan hasil tampilan:
$ douceur inline inputfile.html
Paket pengambilan:
$ go get github.com/aymerick/douceur
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 ())
}
Tampilan:
body {
background-color : black;
}
p {
color : red;
}
package main
import (
"fmt"
"github.com/aymerick/douceur/inliner"
)
func main () {
input := `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
p {
font-family: 'Helvetica Neue', Verdana, sans-serif;
color: #eee;
}
</style>
</head>
<body>
<p>
Inline me please!
</p>
</body>
</html>`
html , err := inliner . Inline ( input )
if err != nil {
panic ( "Please fill a bug :)" )
}
fmt . Print ( html )
}
Tampilan:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > < html xmlns = "http://www.w3.org/1999/xhtml" > < head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
< / head >
< body >
< p style = "color: #eee; font-family: 'Helvetica Neue', Verdana, sans-serif;" >
Inline me please !
< / p >
< / body > < / html >
go test ./... -v