diff options
Diffstat (limited to 'src/Formats')
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 20 | ||||
-rw-r--r-- | src/Formats/HtmlTemplateService.kt | 28 | ||||
-rw-r--r-- | src/Formats/JekyllFormatService.kt | 9 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 10 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 33 | ||||
-rw-r--r-- | src/Formats/TextFormatService.kt | 2 |
6 files changed, 84 insertions, 18 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index e6d09991..550899ff 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -1,7 +1,10 @@ package org.jetbrains.dokka -public open class HtmlFormatService(locationService: LocationService, signatureGenerator: LanguageService) -: StructuredFormatService(locationService, signatureGenerator) { +public open class HtmlFormatService(locationService: LocationService, + resolutionService: ResolutionService, + signatureGenerator: LanguageService, + val templateService: HtmlTemplateService = HtmlTemplateService.default()) +: StructuredFormatService(locationService, resolutionService, signatureGenerator) { override val extension: String = "html" override public fun formatText(text: String): String { @@ -10,13 +13,13 @@ public open class HtmlFormatService(locationService: LocationService, signatureG override fun appendBlockCode(to: StringBuilder, line: String) { to.appendln("<code>") - to.appendln(line) + to.appendln(line.htmlEscape()) to.appendln("</code>") } override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) { to.appendln("<code>") - to.appendln(lines.map { it }.join("\n")) + to.appendln(lines.map { it.htmlEscape() }.join("\n")) to.appendln("</code>") } @@ -75,13 +78,20 @@ public open class HtmlFormatService(locationService: LocationService, signatureG } override fun formatCode(code: String): String { - return "<code>${code}</code>" + return "<code>${code.htmlEscape()}</code>" } override fun formatBreadcrumbs(items: Iterable<FormatLink>): String { return items.map { formatLink(it) }.joinToString(" / ") } + + override fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>) { + templateService.appendHeader(to) + super<StructuredFormatService>.appendNodes(to, nodes) + templateService.appendFooter(to) + } + override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) { } override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { diff --git a/src/Formats/HtmlTemplateService.kt b/src/Formats/HtmlTemplateService.kt new file mode 100644 index 00000000..5bb03fbd --- /dev/null +++ b/src/Formats/HtmlTemplateService.kt @@ -0,0 +1,28 @@ +package org.jetbrains.dokka + +public trait HtmlTemplateService { + fun appendHeader(to: StringBuilder) + fun appendFooter(to: StringBuilder) + + class object { + public fun default(css: String? = null): HtmlTemplateService { + return object : HtmlTemplateService { + override fun appendFooter(to: StringBuilder) { + to.appendln("</BODY>") + to.appendln("</HTML>") + } + override fun appendHeader(to: StringBuilder) { + to.appendln("<HTML>") + to.appendln("<HEAD>") + if (css != null) { + to.appendln("<link rel=\"stylesheet\" href=\"$css\">") + } + to.appendln("</HEAD>") + to.appendln("<BODY>") + } + } + } + } +} + + diff --git a/src/Formats/JekyllFormatService.kt b/src/Formats/JekyllFormatService.kt index aeb1e9ef..459b5113 100644 --- a/src/Formats/JekyllFormatService.kt +++ b/src/Formats/JekyllFormatService.kt @@ -1,12 +1,13 @@ package org.jetbrains.dokka -public class JekyllFormatService(locationService: LocationService, signatureGenerator: LanguageService) -: MarkdownFormatService(locationService, signatureGenerator) { +public class JekyllFormatService(locationService: LocationService, + resolutionService: ResolutionService, + signatureGenerator: LanguageService) +: MarkdownFormatService(locationService, resolutionService, signatureGenerator) { override fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, "html") - override fun appendNodes(to: StringBuilder, - nodes: Iterable<DocumentationNode>) { + override fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>) { to.appendln("---") to.appendln("layout: api") to.appendln("title: ${nodes.first().name}") diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 60e38290..d7530a25 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -1,8 +1,10 @@ package org.jetbrains.dokka -public open class MarkdownFormatService(locationService: LocationService, signatureGenerator: LanguageService) -: StructuredFormatService(locationService, signatureGenerator) { +public open class MarkdownFormatService(locationService: LocationService, + resolutionService: ResolutionService, + signatureGenerator: LanguageService) +: StructuredFormatService(locationService, resolutionService, signatureGenerator) { override val extension: String = "md" @@ -14,6 +16,10 @@ public open class MarkdownFormatService(locationService: LocationService, signat return text.htmlEscape() } + override public fun formatText(text: RichString): String { + return text.toString().htmlEscape() + } + override public fun formatCode(code: String): String { return "`$code`" } 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 } } } diff --git a/src/Formats/TextFormatService.kt b/src/Formats/TextFormatService.kt index b7863c25..29f01a74 100644 --- a/src/Formats/TextFormatService.kt +++ b/src/Formats/TextFormatService.kt @@ -9,7 +9,7 @@ public class TextFormatService(val signatureGenerator: LanguageService) : Format appendln(signatureGenerator.render(node)) appendln() appendln(node.doc.summary) - for (n in node.doc.summary.indices) + for (n in 0..node.doc.summary.length()) append("=") for (section in node.doc.sections) { |