Skip to content

fix: don't add extra newlines when there aren't extra sections in doc markdown #14734

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

Merged
merged 1 commit into from
Mar 22, 2022
Merged
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
22 changes: 12 additions & 10 deletions compiler/src/dotty/tools/dotc/util/ParsedComment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ class ParsedComment(val comment: Comment) {
*
* The different sections are formatted according to the mapping in `knownTags`.
*/
def renderAsMarkdown(using Context): String = {
def renderAsMarkdown(using Context): String =
val buf = new StringBuilder
buf.append(mainDoc + System.lineSeparator + System.lineSeparator)
buf.append(mainDoc)
val groupedSections = CommentParsing.groupedSections(content, tagIndex)

for {
val sections = for {
(tag, formatter) <- ParsedComment.knownTags
boundss <- groupedSections.get(tag)
texts = boundss.map { case (start, end) => clean(content.slice(start, end)) }
formatted <- formatter(texts)
}
{
buf.append(formatted)
buf.append(System.lineSeparator)
}

} yield formatted

if sections.nonEmpty then
buf.append(System.lineSeparator + System.lineSeparator)
sections.foreach { section =>
buf.append(section)
buf.append(System.lineSeparator)
}
buf.toString
}
end renderAsMarkdown

/**
* The `@param` section corresponding to `name`.
Expand Down