Skip to content

Commit

Permalink
feat(markdown): visual improvements & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Jun 16, 2021
1 parent bf8d96a commit 35b7531
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hbollon/go-flags
module github.com/jessevdk/go-flags

go 1.15

Expand Down
17 changes: 9 additions & 8 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ func markdownQuoteLines(s string) string {
}

func markdownQuote(s string) string {
return strings.Replace(s, "\\", "```", -1)
return strings.Replace(s, "\\", "\\\\", -1)
}

func formatForMarkdown(wr io.Writer, s string, quoter func(s string) string) {
for {
idx := strings.IndexRune(s, '`')

fmt.Fprint(wr, " ")
if idx < 0 {
fmt.Fprintf(wr, "%s", quoter(s))
break
Expand Down Expand Up @@ -74,15 +75,15 @@ func writeMarkdownPageOptions(wr io.Writer, grp *Group) {
fmt.Fprintf(wr, "- ")

if opt.ShortName != 0 {
fmt.Fprintf(wr, "**-%c**", opt.ShortName)
fmt.Fprintf(wr, "`-%c`", opt.ShortName)
}

if len(opt.LongName) != 0 {
if opt.ShortName != 0 {
fmt.Fprintf(wr, ", ")
}

fmt.Fprintf(wr, "**\\--%s\\**", markdownQuote(opt.LongNameWithNamespace()))
fmt.Fprintf(wr, "`--%s`", markdownQuote(opt.LongNameWithNamespace()))
}

if len(opt.ValueName) != 0 || opt.OptionalArgument {
Expand All @@ -94,12 +95,12 @@ func writeMarkdownPageOptions(wr io.Writer, grp *Group) {
}

if len(opt.Default) != 0 {
fmt.Fprintf(wr, " <default: *%s*> ", markdownQuote(strings.Join(quoteV(opt.Default), ", ")))
fmt.Fprintf(wr, " <default: *%s*>", markdownQuote(strings.Join(quoteV(opt.Default), ", ")))
} else if len(opt.EnvKeyWithNamespace()) != 0 {
if runtime.GOOS == "windows" {
fmt.Fprintf(wr, " <default: *%%%s%%*> ", markdownQuote(opt.EnvKeyWithNamespace()))
fmt.Fprintf(wr, " <default: *%%%s%%*>", markdownQuote(opt.EnvKeyWithNamespace()))
} else {
fmt.Fprintf(wr, " <default: *$%s*> ", markdownQuote(opt.EnvKeyWithNamespace()))
fmt.Fprintf(wr, " <default: *$%s*>", markdownQuote(opt.EnvKeyWithNamespace()))
}
}

Expand Down Expand Up @@ -193,7 +194,7 @@ func (p *Parser) WriteMarkdownPage(wr io.Writer) {

fmt.Fprintf(wr, "# %s 1 \"%s\"\n", markdownQuote(p.Name), t.Format("2 January 2006"))
fmt.Fprintln(wr, "## NAME")
fmt.Fprintf(wr, "%s \\- %s\n", markdownQuote(p.Name), markdownQuoteLines(p.ShortDescription))
fmt.Fprintf(wr, "### %s \n> %s\n", markdownQuote(p.Name), markdownQuoteLines(p.ShortDescription))
fmt.Fprintln(wr, "## SYNOPSIS")

usage := p.Usage
Expand All @@ -202,7 +203,7 @@ func (p *Parser) WriteMarkdownPage(wr io.Writer) {
usage = "[OPTIONS]"
}

fmt.Fprintf(wr, "**%s** %s\n", markdownQuote(p.Name), markdownQuote(usage))
fmt.Fprintf(wr, "**`%s %s`**\n", markdownQuote(p.Name), markdownQuote(usage))
fmt.Fprintln(wr, "## DESCRIPTION")

formatForMarkdown(wr, p.LongDescription, markdownQuoteLines)
Expand Down

0 comments on commit 35b7531

Please sign in to comment.