aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-07-23 12:38:59 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-19 13:34:10 +0200
commitfc38ceda06d92978175d37bb7197763539c966a2 (patch)
tree69751ac7fd6083fabce8a65bae8e84f85ece5358 /plugins/base/src/main
parenta3880835c4e6c6d0570ab2193be50bd739e9f2ca (diff)
downloaddokka-fc38ceda06d92978175d37bb7197763539c966a2.tar.gz
dokka-fc38ceda06d92978175d37bb7197763539c966a2.tar.bz2
dokka-fc38ceda06d92978175d37bb7197763539c966a2.zip
Make unresolved links render as text
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt14
-rw-r--r--plugins/base/src/main/kotlin/renderers/PackageListService.kt3
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/LocationProvider.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt4
7 files changed, 20 insertions, 17 deletions
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<T>(
open fun T.wrapGroup(node: ContentGroup, pageContext: ContentPage, childrenCallback: T.() -> Unit) =
childrenCallback()
- open fun T.buildLinkText(
+ open fun T.buildText(
nodes: List<ContentNode>,
pageContext: ContentPage,
sourceSetRestriction: Set<DisplaySourceSet>? = null
@@ -109,11 +109,13 @@ abstract class DefaultRenderer<T>(
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<T>(
}
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>()
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<DisplaySourceSet>,
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<DisplaySourceSet>
- ): 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<DisplaySourceSet>, context: PageNode?): String =
+ override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, 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<DisplaySourceSet>, context: PageNode? = null): String
- fun resolve(node: PageNode, context: PageNode? = null, skipExtension: Boolean = false): String
+ fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, 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<PageNode>
}
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<DisplaySourceSet>, context: PageNode?): String =
+ override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, 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)