commands: Add --omitEmpty flag to gen chromastyles

Closes #13475
This commit is contained in:
Joe Mooring 2025-03-06 21:37:23 -08:00 committed by Bjørn Erik Pedersen
parent eebea9ec41
commit 93df17661f
2 changed files with 17 additions and 1 deletions

View file

@ -50,6 +50,7 @@ func newGenCommand() *genCommand {
highlightStyle string
lineNumbersInlineStyle string
lineNumbersTableStyle string
omitEmpty bool
)
newChromaStyles := func() simplecobra.Commander {
@ -79,7 +80,14 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
if err != nil {
return err
}
formatter := html.New(html.WithAllClasses(true))
var formatter *html.Formatter
if omitEmpty {
formatter = html.New(html.WithClasses(true))
} else {
formatter = html.New(html.WithAllClasses(true))
}
w := os.Stdout
fmt.Fprintf(w, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))
formatter.WriteCSS(w, style)
@ -95,6 +103,8 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
_ = cmd.RegisterFlagCompletionFunc("lineNumbersInlineStyle", cobra.NoFileCompletions)
cmd.PersistentFlags().StringVar(&lineNumbersTableStyle, "lineNumbersTableStyle", "", `foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff"`)
_ = cmd.RegisterFlagCompletionFunc("lineNumbersTableStyle", cobra.NoFileCompletions)
cmd.PersistentFlags().BoolVar(&omitEmpty, "omitEmpty", false, `omit empty CSS rules`)
_ = cmd.RegisterFlagCompletionFunc("omitEmpty", cobra.NoFileCompletions)
},
}
}

View file

@ -14,3 +14,9 @@ hugo gen chromastyles --style monokai
stdout 'Generated using: hugo gen chromastyles --style monokai'
! hugo gen chromastyles --style __invalid_style__
stderr 'invalid style: __invalid_style__'
# Issue 13475
hugo gen chromastyles --style monokai
stdout '{ }'
hugo gen chromastyles --omitEmpty --style monokai
! stdout '\{ \}'