aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/HtmlFormatService.kt
blob: 48291b48a6114ac918e73fedfe281bc10ebd98ea (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package org.jetbrains.dokka

public open class HtmlFormatService(locationService: LocationService,
                                    signatureGenerator: LanguageService,
                                    val templateService: HtmlTemplateService = HtmlTemplateService.default())
: StructuredFormatService(locationService, signatureGenerator) {
    override val extension: String = "html"

    override public fun formatText(text: String): String {
        return text.htmlEscape()
    }
    override fun formatSymbol(text: String): String {
        return "<span class=\"symbol\">${formatText(text)}</span>"
    }
    override fun formatKeyword(text: String): String {
        return "<span class=\"keyword\">${formatText(text)}</span>"
    }
    override fun formatIdentifier(text: String): String {
        return "<span class=\"identifier\">${formatText(text)}</span>"
    }

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

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

    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 appendTable(to: StringBuilder, body: () -> Unit) {
        to.appendln("<table>")
        body()
        to.appendln("</table>")
    }

    override fun appendTableHeader(to: StringBuilder, body: () -> Unit) {
        to.appendln("<thead>")
        body()
        to.appendln("</thead>")
    }

    override fun appendTableBody(to: StringBuilder, body: () -> Unit) {
        to.appendln("<tbody>")
        body()
        to.appendln("</tbody>")
    }

    override fun appendTableRow(to: StringBuilder, body: () -> Unit) {
        to.appendln("<tr>")
        body()
        to.appendln("</tr>")
    }

    override fun appendTableCell(to: StringBuilder, body: () -> Unit) {
        to.appendln("<td>")
        body()
        to.appendln("</td>")
    }

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

    override fun formatLink(text: String, href: String): String {
        return "<a href=\"${href}\">${text}</a>"
    }

    override fun formatStrong(text: String): String {
        return "<strong>${text}</strong>"
    }

    override fun formatEmphasis(text: String): String {
        return "<emph>${text}</emph>"
    }

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

    override fun formatList(text: String): String {
        return "<ul>${text}</ul>"
    }

    override fun formatListItem(text: String): String {
        return "<li>${text}</li>"
    }

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


    override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
        templateService.appendHeader(to)
        super<StructuredFormatService>.appendNodes(location, to, nodes)
        templateService.appendFooter(to)
    }

    override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
    }
    override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) {
    }
}