Closed Michael-F-Ellis closed 3 years ago
Thanks Michael!
Huh, yes, the diff should be disabled in this case.
This is where the diff is being set. I don't see any other option but to globally disable it.
I guess we can do it by adding options to the ToMarkdown
function, and propagate it all the way through...
I've got something worked out for my use but it relies on preprocessing before goreadme
sees doc.go. I added code to the section of my build script (magefile) that creates doc.go. It detects leading -
signs and replaces them with \u2010
hyphen runes so that the diff detection doesn't trigger.
// Need to conceal leading '-' chars so goreadme won't interpret them as diff lines.
lines := strings.Split(help, "\n")
for i, line := range lines {
trimmed := strings.TrimLeft(line, " \t")
if strings.HasPrefix(trimmed, "-") {
lines[i] = strings.Replace(line, "-", "\u2010", 1)
}
}
text = strings.Join(lines, "\n")
That solves my problem since I never put diffs in comments, but it's clearly too much of a special case hack to include in goreadme
.
FWIW, I think the best general solution is to add pre and post filter hooks as command line options, e.g.
-PreFilter string
System command applied to the input text on ToMarkdown
-PostFilter string
System command applied to the Markdown output from ToMarkdown
First, thanks for creating
goreadme
. It's a nice solution to a bothersome problem!In a project with several cmds, I'm trying to automatically get the cmd's usage help into the readme. So I wrote some build code to call each installed cmd with "-h" and put the output into doc.go, e.g.
But
goreadme
notices the leading '-' chars and renders the above as: