diff options
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 20 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 14 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 14 | ||||
-rw-r--r-- | src/Languages/KotlinLanguageService.kt | 4 | ||||
-rw-r--r-- | src/Utilities/Html.kt | 7 |
5 files changed, 39 insertions, 20 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 6f81e8eb..406065d6 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -4,28 +4,32 @@ public open class HtmlFormatService(locationService: LocationService, signatureG : StructuredFormatService(locationService, signatureGenerator) { override val extension: String = "html" + override public fun formatText(text: String): String { + return text.htmlEscape() + } + override fun appendBlockCode(to: StringBuilder, line: String) { to.appendln("<code>") - to.appendln(line) + to.appendln(formatText(line)) to.appendln("</code>") } override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) { to.appendln("<code>") - to.appendln(lines.join("\n")) + to.appendln(lines.map { formatText(it) }.join("\n")) to.appendln("</code>") } override fun appendHeader(to: StringBuilder, text: String, level: Int) { - to.appendln("<h$level>$text</h$level>") + to.appendln("<h$level>${formatText(text)}</h$level>") } override fun appendText(to: StringBuilder, text: String) { - to.appendln("<p>$text</p>") + to.appendln("<p>${formatText(text)}</p>") } override fun appendLine(to: StringBuilder, text: String) { - to.appendln("$text<br/>") + to.appendln("${formatText(text)}<br/>") } override fun appendLine(to: StringBuilder) { @@ -33,15 +37,15 @@ public open class HtmlFormatService(locationService: LocationService, signatureG } override fun formatLink(text: String, location: Location): String { - return "<a href=\"${location.path}\">${text}</a>" + return "<a href=\"${location.path}\">${formatText(text)}</a>" } override fun formatBold(text: String): String { - return "<b>$text</b>" + return "<b>${formatText(text)}</b>" } override fun formatCode(code: String): String { - return "<code>$code</code>" + return "<code>${formatText(code)}</code>" } override fun formatBreadcrumbs(items: Iterable<FormatLink>): String { diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 6a76343d..3768c3f1 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -10,6 +10,10 @@ public open class MarkdownFormatService(locationService: LocationService, signat return items.map { formatLink(it) }.joinToString(" / ") } + override public fun formatText(text: String): String { + return text.htmlEscape() + } + override public fun formatCode(code: String): String { return "`$code`" } @@ -27,11 +31,11 @@ public open class MarkdownFormatService(locationService: LocationService, signat } override public fun appendLine(to: StringBuilder, text: String) { - to.appendln(text) + to.appendln(formatText(text)) } override public fun appendText(to: StringBuilder, text: String) { - to.append(text) + to.append(formatText(text)) } override public fun appendHeader(to: StringBuilder, text: String, level: Int) { @@ -41,15 +45,17 @@ public open class MarkdownFormatService(locationService: LocationService, signat } override public fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) { + appendLine(to) appendLine(to, "```") for (line in lines) - appendLine(to, line) + to.appendln(line) appendLine(to, "```") + appendLine(to) } override public fun appendBlockCode(to: StringBuilder, line: String) { appendLine(to, "```") - appendLine(to, line) + to.appendln(line) appendLine(to, "```") } diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 32742fea..87115f8b 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -30,9 +30,12 @@ public abstract class StructuredFormatService(val locationService: LocationServi open public fun appendDescription(to: StringBuilder, nodes: Iterable<DocumentationNode>) { val described = nodes.filter { it.doc.hasDescription } if (described.any()) { - appendHeader(to, "Description") + val single = described.size == 1 + appendHeader(to, "Description", 3) for (node in described) { - appendBlockCode(to, languageService.render(node)) + if (!single) { + appendBlockCode(to, languageService.render(node)) + } appendLine(to, node.doc.description) appendLine(to) for (section in node.doc.sections) { @@ -77,7 +80,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi for (node in nodes) { if (node.members.any()) { - appendHeader(to, "Members") + appendHeader(to, "Members", 3) appendLine(to, "| Name | Summary |") // TODO: hardcoded appendLine(to, "|------|---------|") @@ -90,11 +93,11 @@ public abstract class StructuredFormatService(val locationService: LocationServi for ((summary, items) in breakdownBySummary) { if (!summary.isEmpty()) { appendText(to, summary) - appendText(to, "<br/>") // TODO: hardcoded + to.append("<br/>") // TODO: hardcoded } val signatures = items.map { formatBold(formatCode("${languageService.render(it)}")) } - appendText(to, signatures.join("<br/>")) // TODO: hardcoded + to.append(signatures.join("<br/>")) // TODO: hardcoded } appendLine(to, "|") @@ -115,4 +118,5 @@ public abstract class StructuredFormatService(val locationService: LocationServi } } } + public abstract fun formatText(text: String): String }
\ No newline at end of file diff --git a/src/Languages/KotlinLanguageService.kt b/src/Languages/KotlinLanguageService.kt index 7ae043b0..0b6ae11d 100644 --- a/src/Languages/KotlinLanguageService.kt +++ b/src/Languages/KotlinLanguageService.kt @@ -41,11 +41,11 @@ class KotlinLanguageService : LanguageService { if (node.name == "Function${typeArguments.count() - 1}") { // lambda - return "(${renders.take(renders.size - 1).join()})->${renders.last()}" + return "(${renders.take(renders.size - 1).join()}) -> ${renders.last()}" } if (node.name == "ExtensionFunction${typeArguments.count() - 2}") { // extension lambda - return "${renders.first()}.(${renders.drop(1).take(renders.size - 2).join()})->${renders.last()}" + return "${renders.first()}.(${renders.drop(1).take(renders.size - 2).join()}) -> ${renders.last()}" } if (typeArguments.none()) return node.name diff --git a/src/Utilities/Html.kt b/src/Utilities/Html.kt index a4fd5fae..9630c8cb 100644 --- a/src/Utilities/Html.kt +++ b/src/Utilities/Html.kt @@ -1,4 +1,9 @@ package org.jetbrains.dokka -fun String.htmlEscape() = replace("&", "&").replace("<", "<").replace(">", ">") + +/** + * Replaces symbols reserved in HTML with their respective entities. + * Replaces & with &, < with < and > with > + */ +public fun String.htmlEscape(): String = replace("&", "&").replace("<", "<").replace(">", ">") |