Skip to content

Commit

Permalink
Update renderers for handling multi-line comments:
Browse files Browse the repository at this point in the history
In asciidoc, add hard line breaks (+) only for non-empty lines.
In markdown, add only one hard line break (</br>).
  • Loading branch information
thbkrkr committed Feb 29, 2024
1 parent 8037185 commit b4a8283
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions renderer/asciidoctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ func (adr *AsciidoctorRenderer) RenderFieldDoc(text string) string {
lines := strings.Split(out, "\n")
for i := range lines {
lines[i] = strings.TrimSpace(lines[i])
// Replace newlines with hard line breaks so that newlines are rendered as expected for non-empty lines.
// See: https://docs.asciidoctor.org/asciidoc/latest/blocks/hard-line-breaks
if lines[i] != "" {
lines[i] = lines[i] + " +"
}
}

// Replace newlines with hard line breaks so that newlines are rendered as expected.
// See: https://docs.asciidoctor.org/asciidoc/latest/blocks/hard-line-breaks
return strings.Join(lines, " +\n\n")
return strings.Join(lines, "\n")
}

func (adr *AsciidoctorRenderer) RenderValidation(text string) string {
Expand Down
4 changes: 2 additions & 2 deletions renderer/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func (m *MarkdownRenderer) RenderFieldDoc(text string) string {
// so that including | in a comment does not result in wonky tables.
out := strings.ReplaceAll(text, "|", "\\|")

// Replace newlines with 2 line breaks so that they don't break the Markdown table formatting.
return strings.ReplaceAll(out, "\n", "<br /><br />")
// Replace newlines with 1 line break so that they don't break the Markdown table formatting.
return strings.ReplaceAll(out, "\n", "<br />")
}

func (m *MarkdownRenderer) RenderDefault(text string) string {
Expand Down

0 comments on commit b4a8283

Please sign in to comment.