Skip to content

Commit cf6b600

Browse files
authored
Switch to single style element (#373)
1 parent fa79ac5 commit cf6b600

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Diff for: go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ require (
3636
github.com/jmespath/go-jmespath v0.4.0 // indirect
3737
github.com/mattn/go-runewidth v0.0.14 // indirect
3838
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
39-
github.com/rivo/uniseg v0.4.3 // indirect
39+
github.com/rivo/uniseg v0.4.4 // indirect
4040
github.com/stretchr/testify v1.7.0 // indirect
41-
golang.org/x/image v0.2.0 // indirect
41+
golang.org/x/image v0.5.0 // indirect
4242
golang.org/x/sys v0.5.0 // indirect
4343
golang.org/x/term v0.5.0 // indirect
4444
gopkg.in/yaml.v2 v2.4.0 // indirect

Diff for: go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
251251
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
252252
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
253253
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
254+
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
255+
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
254256
github.com/schollz/progressbar/v3 v3.12.2 h1:yLqqqpQNMxGxHY8uEshRihaHWwa0rf0yb7/Zrpgq2C0=
255257
github.com/schollz/progressbar/v3 v3.12.2/go.mod h1:HFJYIYQQJX32UJdyoigUl19xoV6aMwZt6iX/C30RWfg=
256258
github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8=
@@ -265,6 +267,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
265267
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
266268
golang.org/x/image v0.2.0 h1:/DcQ0w3VHKCC5p0/P2B0JpAZ9Z++V2KOo2fyU89CXBQ=
267269
golang.org/x/image v0.2.0/go.mod h1:la7oBXb9w3YFjBqaAwtynVioc1ZvOnNteUNrifGNmAI=
270+
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
271+
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
268272
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
269273
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
270274
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -307,6 +311,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
307311
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
308312
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
309313
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
314+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
310315
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
311316
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
312317
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

Diff for: manipulations/injectassets/injectassets.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ func addInlineCSS(headNode, bodyNode *html.Node, asset assetmanager.Asset) error
116116
if err != nil {
117117
return err
118118
}
119-
headNode.AppendChild(htmlparsing.InlineCSSTag(c))
119+
style := htmlparsing.FindNodeByTag("style", headNode)
120+
if style == nil {
121+
headNode.AppendChild(htmlparsing.InlineCSSTag(c))
122+
} else {
123+
style.FirstChild.Data += " " + c
124+
}
125+
120126
return nil
121127
}
122128

Diff for: manipulations/injectassets/injectassets_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func TestManipulator(t *testing.T) {
200200
},
201201
},
202202
},
203-
wantHTML: `<html><head><style>example-1 inline contents 1</style><style>example-1 inline contents 2</style><link href="/example-1-sync.css" rel="stylesheet"/></head><body><div class="example-1 example-2"></div><link href="/example-1-async.css" rel="stylesheet" media="print" onload="this.media=&#39;all&#39;"/><link href="/example-1-async.print.css" rel="stylesheet" media="print"/><link href="/example-1-sync.print.css" rel="stylesheet" media="print"/></body></html>`,
203+
wantHTML: `<html><head><style>example-1 inline contents 1 example-1 inline contents 2</style><link href="/example-1-sync.css" rel="stylesheet"/></head><body><div class="example-1 example-2"></div><link href="/example-1-async.css" rel="stylesheet" media="print" onload="this.media=&#39;all&#39;"/><link href="/example-1-async.print.css" rel="stylesheet" media="print"/><link href="/example-1-sync.print.css" rel="stylesheet" media="print"/></body></html>`,
204204
},
205205
{
206206
description: "add preload assets",

0 commit comments

Comments
 (0)