Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions commands/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview
}
options := []html.Option{
html.WithCSSComments(!omitClassComments),
html.WithCustomCSS(chromaCSSOverrides(style)),
}
formatter := html.New(options...)

Expand Down Expand Up @@ -276,33 +275,6 @@ url: %s
}
}

func chromaCSSOverrides(style *chroma.Style) map[chroma.TokenType]string {
bg := style.Get(chroma.Background)
m := make(map[chroma.TokenType]string)
for tt := range chroma.StandardTypes {
if tt == chroma.Background || !style.Has(tt) || !chromaLeafToken(tt) {
continue
}
entry := style.Get(tt)
if !entry.Sub(bg).IsZero() || !entry.Colour.IsSet() {
continue
}
if css := html.StyleEntryToCSS(chroma.StyleEntry{Colour: entry.Colour}); css != "" {
m[tt] = css
}
}
return m
}

func chromaLeafToken(tt chroma.TokenType) bool {
for other := range chroma.StandardTypes {
if other != tt && (other.Category() == tt || other.SubCategory() == tt) {
return false
}
}
return true
}

type genCommand struct {
rootCmd *rootCommand

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gohugoio/hugo
require (
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.1
github.com/alecthomas/chroma/v2 v2.24.1
github.com/alecthomas/chroma/v2 v2.26.1
github.com/aws/aws-sdk-go-v2 v1.41.6
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.61.1
github.com/bep/clocks v0.5.0
Expand Down Expand Up @@ -128,6 +128,7 @@ require (
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/dlclark/regexp2 v1.12.0 // indirect
github.com/dlclark/regexp2/v2 v2.1.1 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.36.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8v
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.24.1 h1:m5ffpfZbIb++k8AqFEKy9uVgY12xIQtBsQlc6DfZJQM=
github.com/alecthomas/chroma/v2 v2.24.1/go.mod h1:l+ohZ9xRXIbGe7cIW+YZgOGbvuVLjMps/FYN/CwuabI=
github.com/alecthomas/chroma/v2 v2.26.1 h1:2X21EdxGZNv5GF9mG5u+uzc02GCFyGxbcBm3Grd9A78=
github.com/alecthomas/chroma/v2 v2.26.1/go.mod h1:lxhRRa9H4hPmRLOOdYga4zkQIQjq3dtrrdwQeCfu78Y=
github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/aws/aws-sdk-go-v2 v1.41.6 h1:1AX0AthnBQzMx1vbmir3Y4WsnJgiydmnJjiLu+LvXOg=
Expand Down Expand Up @@ -209,6 +211,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8=
github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dlclark/regexp2/v2 v2.1.1 h1:LCUGyd9Wf+r+VVOl8Ny38JTpWJcAsdVnCIuhhtthmKw=
github.com/dlclark/regexp2/v2 v2.1.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
12 changes: 0 additions & 12 deletions markup/highlight/highlight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ package highlight
import (
"testing"

"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/styles"

qt "github.com/frankban/quicktest"
)

Expand Down Expand Up @@ -148,12 +145,3 @@ User-Agent: foo
c.Assert(result, qt.Contains, "}")
})
}

func TestGitHubDarkStyleIncludesNameOther(t *testing.T) {
c := qt.New(t)

style := styles.Get("github-dark")
c.Assert(style, qt.Not(qt.IsNil))
c.Assert(style.Has(chroma.NameOther), qt.Equals, true)
c.Assert(style.Get(chroma.NameOther).Colour.String(), qt.Equals, "#e6edf3")
}
7 changes: 1 addition & 6 deletions testscripts/commands/gen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ hugo gen chromastyles --style monokai
hugo gen chromastyles --omitEmpty --style monokai --logLevel info
stderr 'deprecated: --omitEmpty was deprecated'

# Keep same-colour token classes in generated CSS. This is needed when pairing
# styles such as github and github-dark in dual-theme sites.
hugo gen chromastyles --style github-dark
stdout 'NameOther.*\.chroma \.nx \{ color:#e6edf3 \}'

# Disable class comments.
hugo gen chromastyles --style monokai
stdout 'GenericSubheading'
hugo gen chromastyles --omitClassComments --style monokai
! stdout 'GenericSubheading'
! stdout 'GenericSubheading'
Loading