Skip to content

Commit 93df176

Browse files
jmooringbep
authored andcommitted
commands: Add --omitEmpty flag to gen chromastyles
Closes #13475
1 parent eebea9e commit 93df176

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: commands/gen.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func newGenCommand() *genCommand {
5050
highlightStyle string
5151
lineNumbersInlineStyle string
5252
lineNumbersTableStyle string
53+
omitEmpty bool
5354
)
5455

5556
newChromaStyles := func() simplecobra.Commander {
@@ -79,7 +80,14 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
7980
if err != nil {
8081
return err
8182
}
82-
formatter := html.New(html.WithAllClasses(true))
83+
84+
var formatter *html.Formatter
85+
if omitEmpty {
86+
formatter = html.New(html.WithClasses(true))
87+
} else {
88+
formatter = html.New(html.WithAllClasses(true))
89+
}
90+
8391
w := os.Stdout
8492
fmt.Fprintf(w, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))
8593
formatter.WriteCSS(w, style)
@@ -95,6 +103,8 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
95103
_ = cmd.RegisterFlagCompletionFunc("lineNumbersInlineStyle", cobra.NoFileCompletions)
96104
cmd.PersistentFlags().StringVar(&lineNumbersTableStyle, "lineNumbersTableStyle", "", `foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff"`)
97105
_ = cmd.RegisterFlagCompletionFunc("lineNumbersTableStyle", cobra.NoFileCompletions)
106+
cmd.PersistentFlags().BoolVar(&omitEmpty, "omitEmpty", false, `omit empty CSS rules`)
107+
_ = cmd.RegisterFlagCompletionFunc("omitEmpty", cobra.NoFileCompletions)
98108
},
99109
}
100110
}

Diff for: testscripts/commands/gen.txt

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ hugo gen chromastyles --style monokai
1414
stdout 'Generated using: hugo gen chromastyles --style monokai'
1515
! hugo gen chromastyles --style __invalid_style__
1616
stderr 'invalid style: __invalid_style__'
17+
18+
# Issue 13475
19+
hugo gen chromastyles --style monokai
20+
stdout '{ }'
21+
hugo gen chromastyles --omitEmpty --style monokai
22+
! stdout '\{ \}'

0 commit comments

Comments
 (0)