blob: f694ae3e48e16f32a88e6199817374ad3068d80e [file] [log] [blame]
package org.jetbrains.dokka
import com.google.inject.Inject
public open class MarkdownFormatService
@Inject constructor(locationService: LocationService,
signatureGenerator: LanguageService,
linkExtension: String = "md")
: StructuredFormatService(locationService, signatureGenerator, "md", linkExtension) {
override public fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
return items.map { formatLink(it) }.joinToString(" / ")
}
override public fun formatText(text: String): String {
return text.htmlEscape()
}
override fun formatSymbol(text: String): String {
return text.htmlEscape()
}
override fun formatKeyword(text: String): String {
return text.htmlEscape()
}
override fun formatIdentifier(text: String, kind: IdentifierKind): String {
return text.htmlEscape()
}
override public fun formatCode(code: String): String {
return "`$code`"
}
override public fun formatUnorderedList(text: String): String = text + "\n"
override public fun formatOrderedList(text: String): String = text + "\n"
override fun formatListItem(text: String, kind: ListKind): String {
val itemText = if (text.endsWith("\n")) text else text + "\n"
return if (kind == ListKind.Unordered) "* $itemText" else "1. $itemText"
}
override public fun formatStrong(text: String): String {
return "**$text**"
}
override fun formatEmphasis(text: String): String {
return "*$text*"
}
override fun formatStrikethrough(text: String): String {
return "~~$text~~"
}
override fun formatLink(text: String, href: String): String {
return "[$text]($href)"
}
override public fun appendLine(to: StringBuilder) {
to.appendln()
}
override public fun appendLine(to: StringBuilder, text: String) {
to.appendln(text)
}
override fun appendAnchor(to: StringBuilder, anchor: String) {
// no anchors in Markdown
}
override public fun appendParagraph(to: StringBuilder, text: String) {
to.appendln()
to.appendln(text)
to.appendln()
}
override public fun appendHeader(to: StringBuilder, text: String, level: Int) {
appendLine(to)
appendLine(to, "${"#".repeat(level)} $text")
appendLine(to)
}
override public fun appendBlockCode(to: StringBuilder, line: String, language: String) {
appendLine(to)
to.appendln("``` ${language}")
to.appendln(line)
to.appendln("```")
appendLine(to)
}
override fun appendTable(to: StringBuilder, body: () -> Unit) {
to.appendln()
body()
to.appendln()
}
override fun appendTableHeader(to: StringBuilder, body: () -> Unit) {
body()
}
override fun appendTableBody(to: StringBuilder, body: () -> Unit) {
body()
}
override fun appendTableRow(to: StringBuilder, body: () -> Unit) {
to.append("|")
body()
to.appendln()
}
override fun appendTableCell(to: StringBuilder, body: () -> Unit) {
to.append(" ")
body()
to.append(" |")
}
override fun formatNonBreakingSpace(): String = "&nbsp;"
}