mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03:00
commands: Validate style argument passed to gen chromastyles
Closes #13357
This commit is contained in:
parent
1dd27be81a
commit
a352e69b02
2 changed files with 8 additions and 1 deletions
|
@ -21,6 +21,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
|
@ -60,6 +61,10 @@ func newGenCommand() *genCommand {
|
||||||
See https://xyproto.github.io/splash/docs/all.html for a preview of the available styles`,
|
See https://xyproto.github.io/splash/docs/all.html for a preview of the available styles`,
|
||||||
|
|
||||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||||
|
style = strings.ToLower(style)
|
||||||
|
if !slices.Contains(styles.Names(), style) {
|
||||||
|
return fmt.Errorf("invalid style: %s", style)
|
||||||
|
}
|
||||||
builder := styles.Get(style).Builder()
|
builder := styles.Get(style).Builder()
|
||||||
if highlightStyle != "" {
|
if highlightStyle != "" {
|
||||||
builder.Add(chroma.LineHighlight, highlightStyle)
|
builder.Add(chroma.LineHighlight, highlightStyle)
|
||||||
|
|
|
@ -11,4 +11,6 @@ hugo gen man --dir manpages
|
||||||
hugo gen chromastyles -h
|
hugo gen chromastyles -h
|
||||||
stdout 'Generate CSS stylesheet for the Chroma code highlighter'
|
stdout 'Generate CSS stylesheet for the Chroma code highlighter'
|
||||||
hugo gen chromastyles --style monokai
|
hugo gen chromastyles --style monokai
|
||||||
stdout '/\* LineHighlight \*/ \.chroma \.hl \{ background-color:#3c3d38 \}'
|
stdout 'Generated using: hugo gen chromastyles --style monokai'
|
||||||
|
! hugo gen chromastyles --style __invalid_style__
|
||||||
|
stderr 'invalid style: __invalid_style__'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue