Skip to content

Commit b5f34a5

Browse files
authored
Merge pull request #14734 from ckipp01/docCommentMarkdown
fix: don't add extra newlines when there aren't extra sections in doc markdown
2 parents 1d13e17 + 310a90b commit b5f34a5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/util/ParsedComment.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,26 @@ class ParsedComment(val comment: Comment) {
5353
*
5454
* The different sections are formatted according to the mapping in `knownTags`.
5555
*/
56-
def renderAsMarkdown(using Context): String = {
56+
def renderAsMarkdown(using Context): String =
5757
val buf = new StringBuilder
58-
buf.append(mainDoc + System.lineSeparator + System.lineSeparator)
58+
buf.append(mainDoc)
5959
val groupedSections = CommentParsing.groupedSections(content, tagIndex)
6060

61-
for {
61+
val sections = for {
6262
(tag, formatter) <- ParsedComment.knownTags
6363
boundss <- groupedSections.get(tag)
6464
texts = boundss.map { case (start, end) => clean(content.slice(start, end)) }
6565
formatted <- formatter(texts)
66-
}
67-
{
68-
buf.append(formatted)
69-
buf.append(System.lineSeparator)
70-
}
71-
66+
} yield formatted
67+
68+
if sections.nonEmpty then
69+
buf.append(System.lineSeparator + System.lineSeparator)
70+
sections.foreach { section =>
71+
buf.append(section)
72+
buf.append(System.lineSeparator)
73+
}
7274
buf.toString
73-
}
75+
end renderAsMarkdown
7476

7577
/**
7678
* The `@param` section corresponding to `name`.

0 commit comments

Comments
 (0)