diff --git a/doc/rpc/generate.go b/doc/rpc/generate.go --- a/doc/rpc/generate.go +++ b/doc/rpc/generate.go @@ -16,6 +16,7 @@ "os" "os/exec" "path" + "regexp" "strings" "text/template" ) @@ -99,6 +100,38 @@ } else { name := strings.Split(line, " ")[0] desc := run("help", name) + + // Wrap result sections in code blocks + nextIndex := 0 + resultRegex := regexp.MustCompile(`Result.*:`) + for { + resultIndex := resultRegex.FindStringIndex(desc[nextIndex:]) + if resultIndex == nil { + break + } + + start := nextIndex + resultIndex[0] + end := nextIndex + resultIndex[1] + + // Start code block + desc = desc[:end] + "\n```" + desc[end:] + + // End previous code block + if nextIndex != 0 { + desc = desc[:start-1] + "```\n" + desc[start-1:] + } + nextIndex = end + } + + // End previous code block, if there is one + if nextIndex != 0 { + endSectionRegex := regexp.MustCompile(`(?s)\n\n`) + endSectionIndex := endSectionRegex.FindStringIndex(desc[nextIndex:]) + if endSectionIndex != nil { + desc = desc[:nextIndex+endSectionIndex[0]+1] + "```\n" + desc[nextIndex+endSectionIndex[0]+1:] + } + } + comm := Command{ Name: name, Description: desc,