aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/MarkdownFormatService.kt
blob: 9626f62c9a47c825daee5de4e4a3264e15107d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.jetbrains.dokka

import org.jetbrains.dokka.DocumentationNode.Kind

public class MarkdownFormatService(val locationService: LocationService,
                                   val signatureGenerator: SignatureGenerator) : FormatService {
    override val extension: String = "md"
    override fun format(node: DocumentationNode, to: StringBuilder) {
        with (to) {
            appendln(node.path.map { "[${it.name}](${locationService.relativeLocation(node, it, extension)})" }.joinToString(" / "))
            appendln()
            appendln("# ${node.name}")
            appendln(node.doc.summary)
            appendln("```")
            appendln(signatureGenerator.render(node))
            appendln("```")
            appendln(node.doc.description)
            appendln()
            for (section in node.doc.sections) {
                append("##### ")
                append(section.label)
                appendln()
                append(section.text)
                appendln()
            }

            if (node.members.any()) {
                appendln("### Members")
                appendln("| Name | Signature | Summary |")
                appendln("|------|-----------|---------|")
                for (member in node.members.sortBy { it.name }) {
                    val relativePath = locationService.relativeLocation(node, member, extension)
                    val displayName = when (member.kind) {
                        Kind.Constructor -> "*.init*"
                        else -> signatureGenerator.renderName(member).htmlEscape()
                    }
                    append("|[${displayName}](${relativePath})")
                    append("|`${signatureGenerator.render(member)}`")
                    append("|${member.doc.summary} ")
                    appendln("|")
                }
            }
        }
    }
}