From fc38ceda06d92978175d37bb7197763539c966a2 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Thu, 23 Jul 2020 12:38:59 +0200 Subject: Make unresolved links render as text --- plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | 14 ++++++++------ .../base/src/main/kotlin/renderers/PackageListService.kt | 3 ++- .../base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 4 ++-- .../main/kotlin/resolvers/local/BaseLocationProvider.kt | 4 ++-- .../main/kotlin/resolvers/local/DefaultLocationProvider.kt | 4 ++-- .../src/main/kotlin/resolvers/local/LocationProvider.kt | 4 ++-- .../kotlin/resolvers/local/MultimoduleLocationProvider.kt | 4 ++-- 7 files changed, 20 insertions(+), 17 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index ef04bb47..fe2913a4 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -66,7 +66,7 @@ abstract class DefaultRenderer( open fun T.wrapGroup(node: ContentGroup, pageContext: ContentPage, childrenCallback: T.() -> Unit) = childrenCallback() - open fun T.buildLinkText( + open fun T.buildText( nodes: List, pageContext: ContentPage, sourceSetRestriction: Set? = null @@ -109,11 +109,13 @@ abstract class DefaultRenderer( is ContentCodeBlock -> buildCodeBlock(node, pageContext) is ContentCodeInline -> buildCodeInline(node, pageContext) is ContentDRILink -> - buildLink(locationProvider.resolve(node.address, node.sourceSets, pageContext)) { - buildLinkText(node.children, pageContext, sourceSetRestriction) - } + locationProvider.resolve(node.address, node.sourceSets, pageContext)?.let { address -> + buildLink(address) { + buildText(node.children, pageContext, sourceSetRestriction) + } + } ?: buildText(node.children, pageContext, sourceSetRestriction) is ContentResolvedLink -> buildLink(node.address) { - buildLinkText(node.children, pageContext, sourceSetRestriction) + buildText(node.children, pageContext, sourceSetRestriction) } is ContentEmbeddedResource -> buildResource(node, pageContext) is ContentList -> buildList(node, pageContext, sourceSetRestriction) @@ -140,7 +142,7 @@ abstract class DefaultRenderer( } open suspend fun renderPage(page: PageNode) { - val path by lazy { locationProvider.resolve(page, skipExtension = true) } + val path by lazy { locationProvider.resolve(page, skipExtension = true)!! } when (page) { is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".html") is RendererSpecificPage -> when (val strategy = page.strategy) { diff --git a/plugins/base/src/main/kotlin/renderers/PackageListService.kt b/plugins/base/src/main/kotlin/renderers/PackageListService.kt index d4333200..0cf84ddd 100644 --- a/plugins/base/src/main/kotlin/renderers/PackageListService.kt +++ b/plugins/base/src/main/kotlin/renderers/PackageListService.kt @@ -28,7 +28,8 @@ class PackageListService(val context: DokkaContext) { val contentPage = node.safeAs() contentPage?.dri?.forEach { if (parentDris.isNotEmpty() && it.parent !in parentDris) { - nonStandardLocations[it.toString()] = locationProvider.resolve(node) + locationProvider.resolve(node) + ?.let { nodeLocation -> nonStandardLocations[it.toString()] = nodeLocation } } } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 8c2e9c9e..1a2a98b3 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -522,7 +522,7 @@ open class HtmlRenderer( } private fun FlowContent.buildLink(to: PageNode, from: PageNode) = - buildLink(locationProvider.resolve(to, from)) { + buildLink(locationProvider.resolve(to, from)!!) { text(to.name) } @@ -550,7 +550,7 @@ open class HtmlRenderer( platforms: List, from: PageNode? = null, block: FlowContent.() -> Unit - ) = buildLink(locationProvider.resolve(to, platforms.toSet(), from), block) + ) = buildLink(locationProvider.resolve(to, platforms.toSet(), from).orEmpty(), block) override fun buildError(node: ContentNode) { context.logger.error("Unknown ContentNode type: $node") diff --git a/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt index 7387789b..06730641 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt @@ -25,7 +25,7 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) : protected fun getExternalLocation( dri: DRI, sourceSets: Set - ): String { + ): String? { val jdkToExternalDocumentationLinks = dokkaContext.configuration.sourceSets .filter { sourceSet -> sourceSet.sourceSetID in sourceSets.sourceSetIDs } .groupBy({ it.jdkVersion }, { it.externalDocumentationLinks }) @@ -55,7 +55,7 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) : } toResolve.remove(jdk) } - return "" + return null } private fun getLink(dri: DRI, locationInfo: DefaultLocationProvider.LocationInfo): String = diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index b9df45ae..1c27959f 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -48,10 +48,10 @@ open class DefaultLocationProvider( pageGraphRoot.children.forEach { registerPath(it, emptyList()) } } - override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean): String = + override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = pathTo(node, context) + if (!skipExtension) extension else "" - override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?): String = + override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?) = pagesIndex[dri]?.let { resolve(it, context) } ?: anchorsIndex[dri]?.let { resolve(it, context) + "#$dri" } // Not found in PageGraph, that means it's an external link diff --git a/plugins/base/src/main/kotlin/resolvers/local/LocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/LocationProvider.kt index 5077195f..391af004 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/LocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/LocationProvider.kt @@ -6,8 +6,8 @@ import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.pages.RootPageNode interface LocationProvider { - fun resolve(dri: DRI, sourceSets: Set, context: PageNode? = null): String - fun resolve(node: PageNode, context: PageNode? = null, skipExtension: Boolean = false): String + fun resolve(dri: DRI, sourceSets: Set, context: PageNode? = null): String? + fun resolve(node: PageNode, context: PageNode? = null, skipExtension: Boolean = false): String? fun resolveRoot(node: PageNode): String fun ancestors(node: PageNode): List } diff --git a/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt index 75c2ccf6..5d2a96d5 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt @@ -14,12 +14,12 @@ class MultimoduleLocationProvider(private val root: RootPageNode, context: Dokka it.name to it.path }.toMap() - override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?): String = + override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?) = dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames?.let { paths[it] }?.let { "$it/${identifierToFilename(dri.classNames.orEmpty())}/index.html" } ?: defaultLocationProvider.resolve(dri, sourceSets, context) - override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean): String = + override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = defaultLocationProvider.resolve(node, context, skipExtension) override fun resolveRoot(node: PageNode): String = defaultLocationProvider.resolveRoot(node) -- cgit