diff options
author | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2020-10-20 10:57:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 10:57:07 +0200 |
commit | 1abd528eec85fdf92dbdd0447c9322c6690aad37 (patch) | |
tree | 1045f91e653aa40ea4aa7350d22e8b8efc7a7643 /plugins/base/src/main/kotlin/renderers | |
parent | 15f348dc13cd7cf05718adce6e3d43e427fba688 (diff) | |
download | dokka-1abd528eec85fdf92dbdd0447c9322c6690aad37.tar.gz dokka-1abd528eec85fdf92dbdd0447c9322c6690aad37.tar.bz2 dokka-1abd528eec85fdf92dbdd0447c9322c6690aad37.zip |
Fix anchor linking when the linked type is on a different platform (#1568)
* Fix anchor linking when the linked type is on a different platform
* Refactor location provider to use types
Co-authored-by: Marcin Aman <marcin.aman@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index f90a3ace..2a10bdd5 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -9,12 +9,11 @@ import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.base.renderers.TabSortingStrategy -import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint -import org.jetbrains.dokka.base.transformers.pages.sourcelinks.hasTabbedContent import org.jetbrains.dokka.base.renderers.isImage import org.jetbrains.dokka.base.renderers.pageId +import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint +import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.CompositeSourceSetID import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.sourceSetIDs @@ -25,7 +24,6 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.utilities.htmlEscape -import org.jetbrains.dokka.utilities.urlEncoded import java.net.URI open class HtmlRenderer( @@ -833,6 +831,18 @@ open class HtmlRenderer( } } } + + private val ContentNode.isAnchorable: Boolean + get() = anchorLabel != null + + private val ContentNode.anchorLabel: String? + get() = extra[SymbolAnchorHint]?.anchorName + + private val ContentNode.anchor: String? + get() = extra[SymbolAnchorHint]?.contentKind?.let { contentKind -> + (locationProvider as DokkaBaseLocationProvider).anchorForDCI(DCI(dci.dri, contentKind), sourceSets) + } + } fun List<SimpleAttr>.joinAttr() = joinToString(" ") { it.extraKey + "=" + it.extraValue } @@ -842,21 +852,7 @@ private fun String.stripDiv() = drop(5).dropLast(6) // TODO: Find a way to do it private val PageNode.isNavigable: Boolean get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing -fun PropertyContainer<ContentNode>.extraHtmlAttributes() = allOfType<SimpleAttr>() - -val ContentNode.isAnchorable: Boolean - get() = anchorLabel != null - -val ContentNode.anchorLabel: String? - get() = extra[SymbolAnchorHint]?.anchorName - -/** - * Anchors should be unique and should contain sourcesets, dri and contentKind. - * The idea is to make them as short as possible and just use a hashCode from sourcesets in order to match the - * 2040 characters limit - */ -val ContentNode.anchor: String? - get() = extra[SymbolAnchorHint]?.contentKind?.let { contentKind -> (dci.dri.first().toString() + "/" + contentKind + "/" + sourceSets.hashCode()).urlEncoded() } +private fun PropertyContainer<ContentNode>.extraHtmlAttributes() = allOfType<SimpleAttr>() -val ContentNode.sourceSetsFilters: String +private val ContentNode.sourceSetsFilters: String get() = sourceSets.sourceSetIDs.joinToString(" ") { it.toString() } |