aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-12-03 17:52:57 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-12-03 17:52:57 +0100
commit050b0452c82daf75974c0a8f2c26524985d53947 (patch)
tree4a1ef4535271eb517181c31ef6b449beecabbaa9 /core/src/main/kotlin
parent075d4ae427cc93ce0f0ec38f8910ec659bfa1bc6 (diff)
downloaddokka-050b0452c82daf75974c0a8f2c26524985d53947.tar.gz
dokka-050b0452c82daf75974c0a8f2c26524985d53947.tar.bz2
dokka-050b0452c82daf75974c0a8f2c26524985d53947.zip
overload group formatting fixes
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt45
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt4
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt50
4 files changed, 65 insertions, 40 deletions
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index a58319bc..d513e41f 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -41,11 +41,7 @@ public open class HtmlFormatService @Inject constructor(@Named("folders") locati
}
override fun appendLine(to: StringBuilder, text: String) {
- to.appendln("${text}<br/>")
- }
-
- override fun appendLine(to: StringBuilder) {
- to.appendln("<br/>")
+ to.appendln("$text<br/>")
}
override fun appendAnchor(to: StringBuilder, anchor: String) {
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index 4eda7910..870347ab 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -6,6 +6,7 @@ public class KotlinWebsiteFormatService @Inject constructor(locationService: Loc
signatureGenerator: LanguageService)
: JekyllFormatService(locationService, signatureGenerator, "html") {
private var needHardLineBreaks = false
+ private var insideDiv = 0
override fun appendFrontMatter(nodes: Iterable<DocumentationNode>, to: StringBuilder) {
super.appendFrontMatter(nodes, to)
@@ -28,29 +29,53 @@ public class KotlinWebsiteFormatService @Inject constructor(locationService: Loc
override fun formatStrikethrough(text: String): String = "<s>$text</s>"
+ private fun div(to: StringBuilder, cssClass: String, block: () -> Unit) {
+ to.append("<div class=\"$cssClass\">")
+ insideDiv++
+ block()
+ insideDiv--
+ to.append("</div>\n")
+ }
+
override fun appendAsSignature(to: StringBuilder, node: ContentNode, block: () -> Unit) {
val contentLength = node.textLength
if (contentLength == 0) return
- to.append("<div class=\"signature\">")
- needHardLineBreaks = contentLength >= 62
- try {
- block()
- } finally {
- needHardLineBreaks = false
+ div(to, "signature") {
+ needHardLineBreaks = contentLength >= 62
+ try {
+ block()
+ } finally {
+ needHardLineBreaks = false
+ }
}
- to.append("</div>")
}
override fun appendAsOverloadGroup(to: StringBuilder, block: () -> Unit) {
- to.append("<div class=\"overload-group\">\n")
- block()
- to.append("</div>\n")
+ div(to, "overload-group", block)
}
override fun formatLink(text: String, href: String): String {
return "<a href=\"${href}\">${text}</a>"
}
+ override fun appendHeader(to: StringBuilder, text: String, level: Int) {
+ if (insideDiv > 0) {
+ to.appendln("<h$level>${text}</h$level>")
+ }
+ else {
+ super.appendHeader(to, text, level)
+ }
+ }
+
+ override fun appendLine(to: StringBuilder, text: String) {
+ if (insideDiv > 0) {
+ to.appendln("$text<br/>")
+ }
+ else {
+ super.appendLine(to, text)
+ }
+ }
+
override fun appendTable(to: StringBuilder, body: () -> Unit) {
to.appendln("<table class=\"api-docs-table\">")
body()
diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
index f694ae3e..07202b7e 100644
--- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt
+++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
@@ -55,10 +55,6 @@ public open class MarkdownFormatService
return "[$text]($href)"
}
- override public fun appendLine(to: StringBuilder) {
- to.appendln()
- }
-
override public fun appendLine(to: StringBuilder, text: String) {
to.appendln(text)
}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 32a2b68a..324f156a 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -19,8 +19,7 @@ abstract class StructuredFormatService(locationService: LocationService,
abstract fun appendBlockCode(to: StringBuilder, line: String, language: String)
abstract fun appendHeader(to: StringBuilder, text: String, level: Int = 1)
abstract fun appendParagraph(to: StringBuilder, text: String)
- abstract fun appendLine(to: StringBuilder, text: String)
- abstract fun appendLine(to: StringBuilder)
+ abstract fun appendLine(to: StringBuilder, text: String = "")
abstract fun appendAnchor(to: StringBuilder, anchor: String)
abstract fun appendTable(to: StringBuilder, body: () -> Unit)
@@ -114,30 +113,39 @@ abstract class StructuredFormatService(locationService: LocationService,
fun appendDocumentation(location: Location, to: StringBuilder, overloads: Iterable<DocumentationNode>) {
val breakdownBySummary = overloads.groupByTo(LinkedHashMap()) { node -> node.content }
- for ((summary, items) in breakdownBySummary) {
- appendAsOverloadGroup(to) {
- items.forEach {
- val rendered = languageService.render(it)
- appendAsSignature(to, rendered) {
- to.append(formatCode(formatText(location, rendered)))
- it.appendSourceLink(to)
- }
- it.appendOverrides(to)
- it.appendDeprecation(location, to)
- }
- // All items have exactly the same documentation, so we can use any item to render it
- val item = items.first()
- item.details(DocumentationNode.Kind.OverloadGroupNote).forEach {
- to.append(formatText(location, it.content))
+ if (breakdownBySummary.size == 1) {
+ formatOverloadGroup(breakdownBySummary.values.single(), location, to)
+ }
+ else {
+ for ((summary, items) in breakdownBySummary) {
+ appendAsOverloadGroup(to) {
+ formatOverloadGroup(items, location, to)
}
- to.append(formatText(location, item.content.summary))
- appendDescription(location, to, item)
- appendLine(to)
- appendLine(to)
}
}
}
+ private fun formatOverloadGroup(items: MutableList<DocumentationNode>, location: Location, to: StringBuilder) {
+ items.forEach {
+ val rendered = languageService.render(it)
+ appendAsSignature(to, rendered) {
+ to.append(formatCode(formatText(location, rendered)))
+ it.appendSourceLink(to)
+ }
+ it.appendOverrides(to)
+ it.appendDeprecation(location, to)
+ }
+ // All items have exactly the same documentation, so we can use any item to render it
+ val item = items.first()
+ item.details(DocumentationNode.Kind.OverloadGroupNote).forEach {
+ to.append(formatText(location, it.content))
+ }
+ to.append(formatText(location, item.content.summary))
+ appendDescription(location, to, item)
+ appendLine(to)
+ appendLine(to)
+ }
+
private fun DocumentationNode.isModuleOrPackage(): Boolean =
kind == DocumentationNode.Kind.Module || kind == DocumentationNode.Kind.Package