aymerick / douceur Goto Github PK
View Code? Open in Web Editor NEWA simple CSS parser and inliner in Go
License: MIT License
A simple CSS parser and inliner in Go
License: MIT License
The inliner library replaces
is replaced with a space character. In my opinion, inliner should leave
as it is. Here is a short test.
html := `
<html>
<head>
<style type="text/css">
body {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<p> </p>
</body>
</html>`
inline, _ := inliner.Inline(html)
fmt.Println(inline)
This prints:
<html><head>
</head>
<body style="background-color: #f2f2f2;" bgcolor="#f2f2f2">
<p> </p>
</body></html>
Any quick fix for this?
I'm seeing some oddities for this trivial example
package main
import (
"fmt"
"github.com/aymerick/douceur/inliner"
)
func main() {
tmpl := `
<html>
<head>
</head>
<body>
<div>
<table>
{{- range .Trash -}}<tr><td>{{.SomeId}}</td></tr>{{- end -}}
</table>
</div>
</body>
</html>`
compiled, _ := inliner.Inline(tmpl)
fmt.Println(compiled)
}
$ go run example.go
<html><head>
</head>
<body>
<div>
{{- range .Trash -}}{{- end -}}
<table><tbody><tr><td>{{.SomeId}}</td></tr></tbody></table>
</div>
</body></html>
It seems like there are a couple strange things happening here.
tbody
tag is automatically introduced for some reasonThis is more question/feature-request.
I want to preserve the existing CSS selectors after running through the inliner, eg;
Before
<html>
<head>
<style>
.my-class {
color: red;
}
</style>
</head>
<body>
<p class="my-class">Test</p>
</body>
</html>
After
<html>
<head>
<style>
.my-class {
color: red;
}
</style>
</head>
<body>
<p class="my-class" style="color: red;">Test</p>
</body>
</html>
So the my-class
class is both inlined in the p
element as well as preserved in the <style>
header.
The following code loops forever in the latest version:
package css
import (
"testing"
"github.com/aymerick/douceur/parser"
)
func TestInfiniteLoop(t *testing.T) {
parser.Parse(`
@media ( __desktop ) {
background-color: red;
}
`)
}
I use this code for my mail service, but would like to know if there is any activity. I did a lot of refactoring and added Renovate to my fork.
If interested we could integrate the changes into this repo.
Is there any activity on this repo anyway? I noticed old PR's and issues that are not being replied to/merged or resolved in any way
With this CSS
@-webkit-keyframes segment-spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg)
}
}
I get:
Unexpected } character: CHAR (line: 11, column: 1): "}"
I think it's because it's not a recognized "AtRule". This works just fine to parse:
@keyframes segment-spin{
from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}
to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}
}
Vendor prefixes makes me cry at night, but a possible solution would be to extend
this line.
But pardon me, why maintain a list like that? What other strings that starts with a @
can't all be considered "at rules"? E.g this function could be something like:
func (rule *Rule) EmbedsRules() bool {
return strings.HasPrefix(rule.Name, "@")
}
No?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.