@@ -5,19 +5,25 @@ import (
55 "strings"
66
77 "github.com/cli/cli/pkg/iostreams"
8- "github.com/cli/cli/pkg/text "
8+ "github.com/cli/cli/pkg/markdown "
99 "github.com/spf13/cobra"
1010)
1111
1212func referenceHelpFn (cmd * cobra.Command , io * iostreams.IOStreams ) func () string {
1313 cs := io .ColorScheme ()
1414 return func () string {
15- reftext := fmt . Sprintf ( "%s reference\n \n ", cs . Bold ( "gh" ))
15+ reftext := "# gh reference\n \n "
1616
1717 for _ , c := range cmd .Commands () {
1818 reftext += cmdRef (cs , c , 0 )
1919 }
20- return reftext
20+
21+ md , err := markdown .Render (reftext , "auto" )
22+ if err != nil {
23+ return reftext
24+ }
25+
26+ return md
2127 }
2228}
2329
@@ -28,17 +34,34 @@ func cmdRef(cs *iostreams.ColorScheme, cmd *cobra.Command, lvl int) string {
2834 return ref
2935 }
3036
31- cmdColor := cs . Bold
37+ cmdPrefix := "##"
3238 if lvl > 0 {
33- cmdColor = cs . Cyan
39+ cmdPrefix = "###"
3440 }
3541
3642 // Name + Description
37- ref += fmt .Sprintf ("%s%s %s\n " , strings .Repeat (" " , lvl ), cmdColor (cmd .Use ), cmd .Short )
43+ escaped := strings .ReplaceAll (cmd .Use , "<" , "〈" )
44+ escaped = strings .ReplaceAll (escaped , ">" , "〉" )
45+ ref += fmt .Sprintf ("%s %s\n \n " , cmdPrefix , escaped )
46+
47+ ref += cmd .Short + "\n \n "
3848
3949 // Flags
40- ref += text .Indent (dedent (cmd .Flags ().FlagUsages ()), strings .Repeat (" " , lvl + 1 ))
41- ref += text .Indent (dedent (cmd .PersistentFlags ().FlagUsages ()), strings .Repeat (" " , lvl + 1 ))
50+
51+ // TODO glamour doesn't respect linebreaks (double space or backslash at end) at all, so there is
52+ // no way to have the damn flags print without a whole newline in between.
53+ for _ , fu := range strings .Split (cmd .Flags ().FlagUsages (), "\n " ) {
54+ if fu == "" {
55+ continue
56+ }
57+ ref += fu + "\n \n "
58+ }
59+ for _ , fu := range strings .Split (cmd .PersistentFlags ().FlagUsages (), "\n " ) {
60+ if fu == "" {
61+ continue
62+ }
63+ ref += fu + "\n \n "
64+ }
4265
4366 if cmd .HasPersistentFlags () || cmd .HasFlags () || cmd .HasAvailableSubCommands () {
4467 ref += "\n "
0 commit comments