aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/HtmlFormatService.kt
blob: 6c0045090c08643052c23b7e6e1dadca64d84b08 (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
46
47
48
49
50
package org.jetbrains.dokka

public open class HtmlFormatService(locationService: LocationService, signatureGenerator: SignatureGenerator)
: StructuredFormatService(locationService, signatureGenerator) {
    override val extension: String = "html"

    override fun appendBlockCode(to: StringBuilder, line: String) {
        to.appendln("<code>")
        to.appendln(line)
        to.appendln("</code>")
    }

    override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
        to.appendln("<code>")
        to.appendln(lines.join("\n"))
        to.appendln("</code>")
    }

    override fun appendHeader(to: StringBuilder, text: String, level: Int) {
        to.appendln("<h$level>$text</h$level>")
    }

    override fun appendText(to: StringBuilder, text: String) {
        to.appendln("<p>$text</p>")
    }

    override fun appendLine(to: StringBuilder, text: String) {
        to.appendln("$text<br/>")
    }

    override fun appendLine(to: StringBuilder) {
        to.appendln("<br/>")
    }

    override fun formatLink(link: FormatLink): String {
        return "<a href=\"${link.location.path}\">${link.text}</a>"
    }

    override fun formatBold(text: String): String {
        return "<b>$text</b>"
    }

    override fun formatCode(code: String): String {
        return "<code>$code</code>"
    }

    override fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
        return items.map { formatLink(it) }.joinToString("&nbsp;/&nbsp;")
    }
}