From e8b48609229ec0d5a1ac55b4fb0eb79bf93a9a72 Mon Sep 17 00:00:00 2001 From: Charith Ellawala Date: Thu, 8 Aug 2019 10:42:02 +0100 Subject: [PATCH] Add option to preserve trailing whitespace Also adds a `safeIdentifier` template function to strip special characters from anchor identifiers. --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index e0fdf39..e2a9b76 100644 --- a/main.go +++ b/main.go @@ -54,6 +54,9 @@ type generatorConfig struct { // MarkdownDisabled controls markdown rendering for comment lines. MarkdownDisabled bool `json:"markdownDisabled"` + + // PreserveTrailingWhitespace controls retention of trailing whitespace in the rendered document. + PreserveTrailingWhitespace bool `json:"preserveTrailingWhitespace"` } type externalPackage struct { @@ -141,6 +144,10 @@ func main() { return "", errors.Wrap(err, "failed to render the result") } + if config.PreserveTrailingWhitespace { + return b.String(), nil + } + // remove trailing whitespace from each html line for markdown renderers s := regexp.MustCompile(`(?m)^\s+`).ReplaceAllString(b.String(), "") return s, nil @@ -601,6 +608,7 @@ func render(w io.Writer, pkgs []*apiPackage, config generatorConfig) error { "hiddenMember": func(m types.Member) bool { return hiddenMember(m, config) }, "isLocalType": isLocalType, "isOptionalMember": isOptionalMember, + "safeIdentifier": func(s string) string { return regexp.MustCompile("[[:punct:]]+").ReplaceAllLiteralString(s, "-") }, }).ParseGlob(filepath.Join(*flTemplateDir, "*.tpl")) if err != nil { return errors.Wrap(err, "parse error")