aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/StructuredFormatService.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-09-19 22:25:27 +0300
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-09-19 22:25:27 +0300
commit455d74a6a6245969ebd7ec20071b691ed20a2628 (patch)
tree601e80982ddc289d1745a5570347a15512f4fe7d /src/Formats/StructuredFormatService.kt
parentff0c8d7514742b505acff2f2ba51dc21aedbd949 (diff)
downloaddokka-455d74a6a6245969ebd7ec20071b691ed20a2628.tar.gz
dokka-455d74a6a6245969ebd7ec20071b691ed20a2628.tar.bz2
dokka-455d74a6a6245969ebd7ec20071b691ed20a2628.zip
Convert content to RichString and establish resolution service for links.
Diffstat (limited to 'src/Formats/StructuredFormatService.kt')
-rw-r--r--src/Formats/StructuredFormatService.kt33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 5ec86486..339ccf73 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -5,6 +5,7 @@ import java.util.LinkedHashMap
public data class FormatLink(val text: String, val location: Location)
public abstract class StructuredFormatService(val locationService: LocationService,
+ val resolutionService: ResolutionService,
val languageService: LanguageService) : FormatService {
abstract public fun appendBlockCode(to: StringBuilder, line: String)
@@ -27,6 +28,24 @@ public abstract class StructuredFormatService(val locationService: LocationServi
public abstract fun formatCode(code: String): String
public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String
+ open fun formatText(text: RichString): String {
+ return StringBuilder {
+ for (slice in text.slices) {
+ val style = slice.style
+ when (style) {
+ is NormalStyle -> append(slice.text)
+ is BoldStyle -> append(formatBold(slice.text))
+ is CodeStyle -> append(formatCode(slice.text))
+ is LinkStyle -> {
+ val node = resolutionService.resolve(style.link)
+ val location = locationService.location(node)
+ append(formatLink(slice.text, location))
+ }
+ }
+ }
+ }.toString()
+ }
+
open public fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, extension)
open public fun link(from: DocumentationNode, to: DocumentationNode, extension: String): FormatLink {
@@ -34,7 +53,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi
}
open public fun appendDescription(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
- val described = nodes.filter { it.doc.hasDescription }
+ val described = nodes.filter { !it.doc.isEmpty }
if (described.any()) {
val single = described.size == 1
appendHeader(to, "Description", 3)
@@ -59,8 +78,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi
}
for ((summary, items) in breakdownBySummary) {
- appendLine(to, summary)
appendBlockCode(to, items.map { languageService.render(it) })
+ appendLine(to, formatText(summary))
+ appendLine(to)
}
}
@@ -101,13 +121,14 @@ public abstract class StructuredFormatService(val locationService: LocationServi
appendTableCell(to) {
val breakdownBySummary = members.groupBy { it.doc.summary }
for ((summary, items) in breakdownBySummary) {
+ val signatures = items.map { formatCode("${languageService.render(it)}") }
+ for (signature in signatures) {
+ appendText(to, signature)
+ }
+
if (!summary.isEmpty()) {
appendText(to, formatText(summary))
- to.append("<br/>") // TODO: hardcoded
}
-
- val signatures = items.map { formatBold(formatCode("${languageService.render(it)}")) }
- to.append(signatures.join("<br/>")) // TODO: hardcoded
}
}
}