Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to preserve trailing whitespace #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, "-") },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unused?

}).ParseGlob(filepath.Join(*flTemplateDir, "*.tpl"))
if err != nil {
return errors.Wrap(err, "parse error")
Expand Down