blob: 6a76343da242e9dab23ec4100c6a18d4df75d895 [file] [log] [blame]
Ilya Ryzhenkova0bfdbd2014-07-14 15:00:33 +04001package org.jetbrains.dokka
2
Ilya Ryzhenkov68d3bc82014-07-14 19:34:52 +04003
Ilya Ryzhenkov499d0822014-07-15 16:18:53 +04004public open class MarkdownFormatService(locationService: LocationService, signatureGenerator: LanguageService)
Ilya Ryzhenkov62cb5092014-07-15 15:54:05 +04005: StructuredFormatService(locationService, signatureGenerator) {
6
Ilya Ryzhenkova0bfdbd2014-07-14 15:00:33 +04007 override val extension: String = "md"
Ilya Ryzhenkova0bfdbd2014-07-14 15:00:33 +04008
Ilya Ryzhenkov62cb5092014-07-15 15:54:05 +04009 override public fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
10 return items.map { formatLink(it) }.joinToString(" / ")
Ilya Ryzhenkovcd7084d2014-07-14 21:15:04 +040011 }
12
Ilya Ryzhenkov62cb5092014-07-15 15:54:05 +040013 override public fun formatCode(code: String): String {
14 return "`$code`"
Ilya Ryzhenkovcd7084d2014-07-14 21:15:04 +040015 }
16
Ilya Ryzhenkov62cb5092014-07-15 15:54:05 +040017 override public fun formatBold(text: String): String {
18 return "**$text**"
Ilya Ryzhenkova0bfdbd2014-07-14 15:00:33 +040019 }
Ilya Ryzhenkovcd7084d2014-07-14 21:15:04 +040020
Ilya Ryzhenkov499d0822014-07-15 16:18:53 +040021 override public fun formatLink(text: String, location: Location): String {
22 return "[${text}](${location.path})"
Ilya Ryzhenkov62cb5092014-07-15 15:54:05 +040023 }
24
25 override public fun appendLine(to: StringBuilder) {
26 to.appendln()
27 }
28
29 override public fun appendLine(to: StringBuilder, text: String) {
30 to.appendln(text)
31 }
32
33 override public fun appendText(to: StringBuilder, text: String) {
34 to.append(text)
35 }
36
37 override public fun appendHeader(to: StringBuilder, text: String, level: Int) {
38 appendLine(to)
39 appendLine(to, "${"#".repeat(level)} $text")
40 appendLine(to)
41 }
42
43 override public fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
44 appendLine(to, "```")
45 for (line in lines)
46 appendLine(to, line)
47 appendLine(to, "```")
48 }
49
50 override public fun appendBlockCode(to: StringBuilder, line: String) {
51 appendLine(to, "```")
52 appendLine(to, line)
53 appendLine(to, "```")
54 }
Ilya Ryzhenkov499d0822014-07-15 16:18:53 +040055
56 var outlineLevel = 0
57 override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) {
58 val indent = " ".repeat(outlineLevel)
59 appendLine(to, "$indent- title: ${languageService.renderName(node)}")
60 appendLine(to, "$indent url: ${locationService.location(node).path}")
61 }
62
63 override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
64 val indent = " ".repeat(outlineLevel)
65 appendLine(to, "$indent content:")
66 outlineLevel++
67 for (node in nodes) {
68 appendOutlineHeader(to, node)
69 if (node.members.any()) {
70 appendOutlineChildren(to, node.members)
71 }
72 appendLine(to)
73 }
74 outlineLevel--
75 }
Ilya Ryzhenkov68d3bc82014-07-14 19:34:52 +040076}