diff --git a/renderer/src/main/kotlin/renderer3/MkDocsRenderer3.kt b/renderer/src/main/kotlin/renderer3/MkDocsRenderer3.kt index 5772411..49d156e 100644 --- a/renderer/src/main/kotlin/renderer3/MkDocsRenderer3.kt +++ b/renderer/src/main/kotlin/renderer3/MkDocsRenderer3.kt @@ -105,7 +105,6 @@ class MkDocsRenderer3( with(context) { buildFrontMatter() - buildNavigation() buildContent(page.content) } diff --git a/renderer/src/main/kotlin/renderer3/Page.kt b/renderer/src/main/kotlin/renderer3/Page.kt index 35deea3..162ac01 100644 --- a/renderer/src/main/kotlin/renderer3/Page.kt +++ b/renderer/src/main/kotlin/renderer3/Page.kt @@ -45,27 +45,5 @@ internal fun RenderingContext.buildFrontMatter() { appendLine() } -internal fun RenderingContext.buildNavigation() { - var first = true - - val targets = locations.ancestors(page).asReversed() - .filter { it.name.isNotBlank() } - .takeIf { it.size > 1 } // Don't render the navigation bar for module pages - ?.forEach { node -> - if (first) { - first = false - } else { - append(" • ") - } - - if (node.isNavigable) buildLink(node, page) - else append(node.name) - } - appendLine() - if (targets != null) - appendLine(" { data-search-exclude }") - appendLine() -} - private val PageNode.isNavigable: Boolean get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing -- 2.51.2 From d4230f19441009bb8381de3bf7c1fca6bebc13c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 7 Feb 2026 12:37:01 +0100 Subject: [PATCH 2/3] feat(renderer1): Delete the renderer v1 --- .../main/kotlin/renderer/MkDocsRenderer.kt | 477 ------------------ 1 file changed, 477 deletions(-) delete mode 100644 renderer/src/main/kotlin/renderer/MkDocsRenderer.kt diff --git a/renderer/src/main/kotlin/renderer/MkDocsRenderer.kt b/renderer/src/main/kotlin/renderer/MkDocsRenderer.kt deleted file mode 100644 index ce1f5d1..0000000 --- a/renderer/src/main/kotlin/renderer/MkDocsRenderer.kt +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright 2014-2024 JetBrains s.r.o & OpenSavvy. Use of this source code is governed by the Apache 2.0 license. - */ - -package opensavvy.dokka.material.mkdocs.renderer - -import opensavvy.dokka.material.mkdocs.GfmCommand.Companion.templateCommand -import opensavvy.dokka.material.mkdocs.MaterialForMkDocsPlugin -import opensavvy.dokka.material.mkdocs.ResolveLinkGfmCommand -import org.jetbrains.dokka.DokkaException -import org.jetbrains.dokka.InternalDokkaApi -import org.jetbrains.dokka.base.renderers.DefaultRenderer -import org.jetbrains.dokka.base.renderers.isImage -import org.jetbrains.dokka.model.DisplaySourceSet -import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.plugability.plugin -import org.jetbrains.dokka.plugability.query -import org.jetbrains.dokka.transformers.pages.PageTransformer -import org.jetbrains.dokka.utilities.htmlEscape - -open class MkDocsRenderer( - context: DokkaContext, -) : DefaultRenderer(context) { - - override val preprocessors: List = context.plugin().query { mkdocsPreprocessor } - - private val isPartial = context.configuration.delayTemplateSubstitution - - override fun StringBuilder.wrapGroup( - node: ContentGroup, - pageContext: ContentPage, - childrenCallback: StringBuilder.() -> Unit, - ) { - return when { - node.hasStyle(TextStyle.Block) || node.hasStyle(TextStyle.Paragraph) -> { - buildParagraph() - childrenCallback() - buildParagraph() - } - - node.hasStyle(TextStyle.Monospace) -> { - append("
") - append("
")
-				append("")
-				append("")
-				childrenCallback()
-				append("")
-				append("")
-				append("
") - append("
") - Unit - } - - node.dci.kind == ContentKind.Deprecation -> { - append("---") - childrenCallback() - append("---") - buildNewLine() - } - - node.hasStyle(ContentStyle.Footnote) -> { - childrenCallback() - buildParagraph() - } - - else -> childrenCallback() - } - } - - override fun StringBuilder.buildHeader(level: Int, node: ContentHeader, content: StringBuilder.() -> Unit) { - buildParagraph() - append("#".repeat(level) + " ") - content() - buildParagraph() - } - - override fun StringBuilder.buildLink(address: String, content: StringBuilder.() -> Unit) { - append("") - content() - append("") - } - - override fun StringBuilder.buildList( - node: ContentList, - pageContext: ContentPage, - sourceSetRestriction: Set?, - ) { - buildParagraph() - buildList(node, pageContext) - buildParagraph() - } - - private fun StringBuilder.buildList( - node: ContentList, - pageContext: ContentPage, - ) { - node.children.forEachIndexed { i, it -> - if (node.ordered) { - // number is irrelevant, but a nice touch - // period is more widely compatible - append("${i + 1}. ") - } else { - append("- ") - } - - /* - Handle case when list item transitions to another complex node with no preceding text. - For example, the equivalent of: -
  • -
      • Item
    -
  • - - Would be: - - - - Item - */ - if (it is ContentGroup && it.children.firstOrNull()?.let { it !is ContentText } == true) { - append("\n ") - } - - buildString { it.build(this, pageContext, it.sourceSets) } - .replace("\n", "\n ") // apply indent - .trim().let { append(it) } - buildNewLine() - } - } - - override fun StringBuilder.buildDRILink( - node: ContentDRILink, - pageContext: ContentPage, - sourceSetRestriction: Set?, - ) { - val location = locationProvider.resolve(node.address, node.sourceSets, pageContext) - if (location == null) { - if (isPartial) { - templateCommand(ResolveLinkGfmCommand(node.address)) { - buildText(node.children, pageContext, sourceSetRestriction) - } - } else { - buildText(node.children, pageContext, sourceSetRestriction) - } - } else { - buildLink(location) { - buildText(node.children, pageContext, sourceSetRestriction) - } - } - } - - override fun StringBuilder.buildLineBreak() { - append("
    ") - buildNewLine() - } - - private fun StringBuilder.buildNewLine() { - append("\n") - } - - private fun StringBuilder.buildParagraph() { - buildNewLine() - buildNewLine() - } - - override fun StringBuilder.buildPlatformDependent( - content: PlatformHintedContent, - pageContext: ContentPage, - sourceSetRestriction: Set?, - ) { - buildPlatformDependentItem(content.inner, content.sourceSets, pageContext) - } - - private fun StringBuilder.buildPlatformDependentItem( - content: ContentNode, - sourceSets: Set, - pageContext: ContentPage, - ) { - if (content is ContentGroup && content.children.firstOrNull { it is ContentTable } != null) { - buildContentNode(content, pageContext, sourceSets) - } else { - val distinct = sourceSets.map { - it to buildString { buildContentNode(content, pageContext, setOf(it)) } - }.groupBy(Pair::second, Pair::first) - - distinct.filter { it.key.isNotBlank() }.forEach { (text, platforms) -> - buildParagraph() - buildSourceSetTags(platforms.toSet()) - buildLineBreak() - append(text.trim()) - buildParagraph() - } - } - } - - override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) { - if (node.isImage()) { - append("!") - } - append("[${node.altText}](${node.address})") - } - - override fun StringBuilder.buildTable( - node: ContentTable, - pageContext: ContentPage, - sourceSetRestriction: Set?, - ) { - buildNewLine() - - if (node.dci.kind == ContentKind.Parameters) { - appendLine("\n
    ") - for (parameter in node.children) { - val (name, description) = parameter.children - name as ContentText - description as ContentGroup - appendLine("
    \n") - buildText(name) - appendLine("\n\n\n
    \n") - buildText(description.children, pageContext, sourceSetRestriction) - appendLine("\n\n
    ") - } - - appendLine("
    ") - } else if (node.dci.kind == ContentKind.Sample) { - node.sourceSets.forEach { sourcesetData -> - append(sourcesetData.name) - buildNewLine() - buildTable( - node.copy( - children = node.children.filter { it.sourceSets.contains(sourcesetData) }, - dci = node.dci.copy(kind = ContentKind.Main) - ), pageContext, sourceSetRestriction - ) - buildNewLine() - } - } else { - val size = node.header.firstOrNull()?.children?.size ?: node.children.firstOrNull()?.children?.size ?: 0 - if (size <= 0) return - - if (node.header.isNotEmpty()) { - node.header.forEach { - it.children.forEach { - append("| ") - it.build(this, pageContext, it.sourceSets) - append(" ") - } - } - } else { - append("| ".repeat(size)) - } - append("|") - buildNewLine() - - append("|---".repeat(size)) - append("|") - buildNewLine() - - node.children.forEach { row -> - row.children.forEach { cell -> - append("| ") - append(buildString { cell.build(this, pageContext) } - .trim() - .replace("#+ ".toRegex(), "") // Workaround for headers inside tables - .replace("\\\n", "\n\n") - .replace("\n[\n]+".toRegex(), "
    ") - .replace("\n", " ") - ) - append(" ") - } - append("|") - buildNewLine() - } - } - } - - @OptIn(InternalDokkaApi::class) - override fun StringBuilder.buildText(textNode: ContentText) { - if (textNode.extra[HtmlContent] != null) { - append(textNode.text) - } else if (textNode.text.isNotBlank()) { - val decorators = decorators(textNode.style) - append(textNode.text.takeWhile { it == ' ' }) - for (decorator in decorators) append(decorator.start) - append(textNode.text.trim().htmlEscape()) - for (decorator in decorators.reversed()) append(decorator.end) - append(textNode.text.takeLastWhile { it == ' ' }) - } - } - - override fun StringBuilder.buildNavigation(page: PageNode) { - var first = true - - locationProvider.ancestors(page).asReversed() - .filter { it.name.isNotBlank() } - .forEach { node -> - if (first) { - first = false - } else { - append(" • ") - } - - if (node.isNavigable) buildLink(node, page) - else append(node.name) - } - - buildParagraph() - } - - override fun buildPage(page: ContentPage, content: (StringBuilder, ContentPage) -> Unit): String = - buildString { - content(this, page) - }.trim().replace("\n[\n]+".toRegex(), "\n\n") - - override fun buildError(node: ContentNode) { - context.logger.warn("Markdown renderer has encountered problem. The unmatched node is $node") - } - - override fun StringBuilder.buildDivergent(node: ContentDivergentGroup, pageContext: ContentPage) { - - val distinct = - node.groupDivergentInstances(pageContext, { instance, _, sourceSet -> - instance.before?.let { before -> - buildString { buildContentNode(before, pageContext, sourceSet) } - } ?: "" - }, { instance, _, sourceSet -> - instance.after?.let { after -> - buildString { buildContentNode(after, pageContext, sourceSet) } - } ?: "" - }) - - distinct.values.forEach { entry -> - val (instance, sourceSets) = entry.getInstanceAndSourceSets() - - buildParagraph() - buildSourceSetTags(sourceSets) - buildLineBreak() - - instance.before?.let { - buildContentNode( - it, - pageContext, - sourceSets.first() - ) // It's workaround to render content only once - buildParagraph() - } - - entry.groupBy { buildString { buildContentNode(it.first.divergent, pageContext, setOf(it.second)) } } - .values.forEach { innerEntry -> - val (innerInstance, innerSourceSets) = innerEntry.getInstanceAndSourceSets() - if (sourceSets.size > 1) { - buildSourceSetTags(innerSourceSets) - buildLineBreak() - } - innerInstance.divergent.build( - this@buildDivergent, - pageContext, - setOf(innerSourceSets.first()) - ) // It's workaround to render content only once - buildParagraph() - } - - instance.after?.let { - buildContentNode( - it, - pageContext, - sourceSets.first() - ) // It's workaround to render content only once - } - - buildParagraph() - } - } - - override fun StringBuilder.buildCodeBlock(code: ContentCodeBlock, pageContext: ContentPage) { - append("```") - append(code.language.ifEmpty { "kotlin" }) - buildNewLine() - code.children.forEach { - if (it is ContentText) { - // since this is a code block where text will be rendered as is, - // no need to escape text, apply styles, etc. Just need the plain value - append(it.text) - } else if (it is ContentBreakLine) { - // since this is a code block where text will be rendered as is, - // there's no need to add tailing slash for line breaks - buildNewLine() - } - } - buildNewLine() - append("```") - buildNewLine() - } - - override fun StringBuilder.buildCodeInline(code: ContentCodeInline, pageContext: ContentPage) { - append("`") - code.children.filterIsInstance().forEach { append(it.text) } - append("`") - } - - private fun decorators(styles: Set