From 0d2ee179b6563020874db9f60906fb16b6ae1556 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 7 Oct 2020 14:40:09 +0200 Subject: Add information about content kind and sourceset to anchor --- .../main/kotlin/allModulePage/MultimodulePageCreator.kt | 2 +- .../base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 4 ++-- .../base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt | 14 ++++++++------ .../main/kotlin/resolvers/local/DokkaLocationProvider.kt | 2 +- .../pages/sourcelinks/SourceLinksTransformer.kt | 2 +- .../kotlin/translators/documentables/DefaultPageCreator.kt | 6 +++--- .../kotlin/translators/documentables/PageContentBuilder.kt | 4 ++-- 7 files changed, 18 insertions(+), 16 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt index 5ae8f04a..80a06a89 100644 --- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt +++ b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt @@ -48,7 +48,7 @@ class MultimodulePageCreator( val displayedModuleDocumentation = getDisplayedModuleDocumentation(module) val dri = DRI(packageName = MULTIMODULE_PACKAGE_PLACEHOLDER, classNames = module.name) val dci = DCI(setOf(dri), ContentKind.Comment) - val extraWithAnchor = PropertyContainer.withAll(SymbolAnchorHint(module.name)) + val extraWithAnchor = PropertyContainer.withAll(SymbolAnchorHint(module.name, ContentKind.Main)) val header = linkNode(module.name, dri, DCI(setOf(dri), ContentKind.Main), extra = extraWithAnchor) val content = ContentGroup( children = diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index ef5d78b6..07cba90c 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -844,7 +844,7 @@ val ContentNode.isAnchorable: Boolean get() = anchorLabel != null val ContentNode.anchorLabel: String? - get() = extra[SymbolAnchorHint.SymbolAnchorHintKey]?.anchorName + get() = extra[SymbolAnchorHint]?.anchorName val ContentNode.anchor: String - get() = dci.dri.first().toString().urlEncoded() + get() = (dci.dri.first().toString() + "/" + extra[SymbolAnchorHint]?.contentKind + "/" + sourceSets.joinToString { it.sourceSetIDs.all.joinToString() }).urlEncoded() diff --git a/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt b/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt index 0b68db10..8f633b70 100644 --- a/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt +++ b/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt @@ -3,11 +3,13 @@ package org.jetbrains.dokka.base.resolvers.anchors import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.pages.ContentNode +import org.jetbrains.dokka.pages.Kind -data class SymbolAnchorHint(val anchorName: String): ExtraProperty { - object SymbolAnchorHintKey : ExtraProperty.Key - override val key: ExtraProperty.Key = SymbolAnchorHintKey - companion object: ExtraProperty.Key { - fun from(d: Documentable): SymbolAnchorHint? = d.name?.let { SymbolAnchorHint(it) } +data class SymbolAnchorHint(val anchorName: String, val contentKind: Kind) : ExtraProperty { + override val key: ExtraProperty.Key = SymbolAnchorHint + + companion object : ExtraProperty.Key { + fun from(d: Documentable, contentKind: Kind): SymbolAnchorHint? = + d.name?.let { SymbolAnchorHint(it, contentKind) } } -} \ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt index a89aed9a..fe8c8f84 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt @@ -44,7 +44,7 @@ open class DokkaLocationProvider( pageGraphRoot.withDescendants().filterIsInstance() .flatMap { page -> page.content.withDescendants() - .filter { it.extra[SymbolAnchorHint.SymbolAnchorHintKey] != null } + .filter { it.extra[SymbolAnchorHint] != null } .mapNotNull { it.dci.dri.singleOrNull() } .distinct() .flatMap { dri -> diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt index 8e1e99f2..069d1125 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -64,7 +64,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent +ContentTable( emptyList(), sources.map { - buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source, extra = mainExtra + SymbolAnchorHint(it.second)) { + buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source, extra = mainExtra + SymbolAnchorHint(it.second, ContentKind.Source)) { link("(source)", it.second) } }, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index caeb6bcb..6c1b5ea4 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -186,7 +186,7 @@ open class DefaultPageCreator( .groupBy({ it.second }, { it.first }).map { (classlike, platforms) -> val label = classlike.classNames?.substringBeforeLast(".") ?: classlike.toString() .also { logger.warn("No class name found for DRI $classlike") } - buildGroup(setOf(dri), platforms.toSet(), ContentKind.Inheritors, extra = mainExtra + SymbolAnchorHint(label)) { + buildGroup(setOf(classlike), platforms.toSet(), ContentKind.Inheritors, extra = mainExtra + SymbolAnchorHint(label, ContentKind.Inheritors)) { link(label, classlike) } }, @@ -530,7 +530,7 @@ open class DefaultPageCreator( sourceSets = elements.flatMap { it.sourceSets }.toSet(), kind = kind, styles = emptySet(), - extra = elementName?.let { name -> extra + SymbolAnchorHint(name) } ?: extra + extra = elementName?.let { name -> extra + SymbolAnchorHint(name, kind) } ?: extra ) { link(elementName.orEmpty(), elements.first().dri, kind = kind) divergentGroup( @@ -540,7 +540,7 @@ open class DefaultPageCreator( extra = extra ) { elements.map { - instance(setOf(it.dri), it.sourceSets.toSet(), extra = PropertyContainer.withAll(SymbolAnchorHint(it.name ?: ""))) { + instance(setOf(it.dri), it.sourceSets.toSet(), extra = PropertyContainer.withAll(SymbolAnchorHint(it.name ?: "", kind))) { divergent { group { +buildSignature(it) diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index c67fe4b0..1865f276 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -115,7 +115,7 @@ open class PageContentBuilder( sourceSets, kind, styles, - extra + SymbolAnchorHint(text.replace("\\s".toRegex(), "").toLowerCase()) + extra + SymbolAnchorHint(text.replace("\\s".toRegex(), "").toLowerCase(), kind) ) { text(text, kind = kind) block() @@ -185,7 +185,7 @@ open class PageContentBuilder( else it } .map { - val newExtra = if (needsAnchors) extra + SymbolAnchorHint.from(it) else extra + val newExtra = if (needsAnchors) extra + SymbolAnchorHint.from(it, kind) else extra buildGroup(setOf(it.dri), it.sourceSets.toSet(), kind, styles, newExtra) { operation(it) } -- cgit