Skip to content

Commit

Permalink
crd: Respect multiline comments at godocs
Browse files Browse the repository at this point in the history
Sometimes at type has examples about how to use it embedding something
like a yaml on it, yamls should not be truncated and they are white
space sensitive. This change keep the new lines and also remove the
white space trimming only on /* comments.

Signed-off-by: Enrique Llorente <ellorent@redhat.com>
  • Loading branch information
qinqon committed Dec 20, 2023
1 parent 943de6e commit 68cbc38
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/markers/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func extractDoc(node ast.Node, decl *ast.GenDecl) string {
}
outGroup.List = append(outGroup.List, comment)
}
isAsteriskComment := false
for _, l := range outGroup.List {
if strings.HasPrefix(l.Text, "/*") {
isAsteriskComment = true
break
}
}

// split lines, and re-join together as a single
// paragraph, respecting double-newlines as
Expand All @@ -69,10 +76,12 @@ func extractDoc(node ast.Node, decl *ast.GenDecl) string {
}

for i, line := range outLines {
// Trim any extranous whitespace,
// for handling /*…*/-style comments,
// which have whitespace preserved in go/ast:
line = strings.TrimSpace(line)
if isAsteriskComment {
// Trim any extranous whitespace,
// for handling /*…*/-style comments,
// which have whitespace preserved in go/ast:
line = strings.TrimSpace(line)
}

// Respect that double-newline means
// actual newline:
Expand All @@ -82,8 +91,7 @@ func extractDoc(node ast.Node, decl *ast.GenDecl) string {
outLines[i] = line
}
}

return strings.Join(outLines, " ")
return strings.Join(outLines, "\n")
}

// PackageMarkers collects all the package-level marker values for the given package.
Expand Down

0 comments on commit 68cbc38

Please sign in to comment.