package org.jetbrains.dokka.renderers import org.jetbrains.dokka.htmlEscape import org.jetbrains.dokka.pages.ContentLink import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.resolvers.LocationProvider import java.io.File import java.io.InputStreamReader open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvider): DefaultRenderer(fileWriter, locationProvider) { override fun buildComment(parts: List, pageContext: PageNode): String = "

${super.buildComment(parts, pageContext)}

" override fun buildSymbol(parts: List, pageContext: PageNode): String = "${super.buildSymbol(parts, pageContext)}" override fun buildHeader(level: Int, text: String): String = "$text\n" override fun buildNewLine(): String = "
" override fun buildLink(text: String, address: String): String = "${text.htmlEscape()}" override fun buildCode(code: String): String = "$code" override fun buildText(text: String) = super.buildText(text).htmlEscape() override fun buildNavigation(page: PageNode): String { fun buildNavigationWithContext(page: PageNode, context: PageNode): String = page.parent?.let { buildNavigationWithContext(it, context) }.orEmpty() + "/" + buildLink(page.name, locationProvider.resolve(page, context)) return buildNavigationWithContext(page, page) } override fun buildGroup(children: List, pageContext: PageNode): String = children.find { it is ContentLink }?.build(pageContext) + "\n" + "" + children.filterNot { it is ContentLink }.joinToString("\n") { it.build(pageContext) } override fun buildBlock(name: String, content: List, pageContext: PageNode): String = buildHeader(3, name) + "\n\n\n\n\n\n
\n" + content.joinToString("
") { it.build(pageContext) } + "
" override fun renderPage(page: PageNode) { val pageText = buildStartHtml(page) + buildPageContent(page) + buildEndHtml() fileWriter.write(locationProvider.resolve(page), pageText, "") } override fun buildSupportFiles() { fileWriter.write("style.css", InputStreamReader(javaClass.getResourceAsStream("/dokka/styles/style.css")).readText()) } protected open fun buildStartHtml(page: PageNode) = """ | | |${page.name} | | | |""".trimMargin() protected open fun buildEndHtml() = """ | | | """.trimMargin() }