aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
authorFilip Zybała <fzybala@virtuslab.com>2020-04-14 14:29:35 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-20 14:53:12 +0200
commit5b6e8564808c3ab2ebe5b94c2a7e59971bfc4003 (patch)
treee43353cc990132146fb4c3c9539d1948d59762b1 /plugins/base
parentec9f4b3386ef979196e00334172051ece9a95acf (diff)
downloaddokka-5b6e8564808c3ab2ebe5b94c2a7e59971bfc4003.tar.gz
dokka-5b6e8564808c3ab2ebe5b94c2a7e59971bfc4003.tar.bz2
dokka-5b6e8564808c3ab2ebe5b94c2a7e59971bfc4003.zip
Added anchors for symbols and headers on page
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt65
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt2
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt26
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt16
5 files changed, 67 insertions, 46 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
index a089f8f5..1684f819 100644
--- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
@@ -23,7 +23,7 @@ abstract class DefaultRenderer<T>(
protected open val preprocessors: Iterable<PageTransformer> = emptyList()
- abstract fun T.buildHeader(level: Int, content: T.() -> Unit)
+ abstract fun T.buildHeader(level: Int, node: ContentHeader, content: T.() -> Unit)
abstract fun T.buildLink(address: String, content: T.() -> Unit)
abstract fun T.buildList(
node: ContentList,
@@ -78,7 +78,7 @@ abstract class DefaultRenderer<T>(
pageContext: ContentPage,
sourceSetRestriction: Set<SourceSetData>? = null
) {
- buildHeader(node.level) { node.children.forEach { it.build(this, pageContext, sourceSetRestriction) } }
+ buildHeader(node.level, node) { node.children.forEach { it.build(this, pageContext, sourceSetRestriction) } }
}
open fun ContentNode.build(
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 64c03bc7..388ee72f 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -197,29 +197,31 @@ open class HtmlRenderer(
.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
.takeIf { it.isNotEmpty() }
?.let {
- div(classes = "table-row") {
- it.filterIsInstance<ContentLink>().takeIf { it.isNotEmpty() }?.let {
- div("main-subrow " + node.style.joinToString(" ")) {
- it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
- .forEach {
- it.build(this, pageContext, sourceSetRestriction)
- if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1))
- createPlatformTags(node)
- }
+ withAnchor(node.dci.dri.first().toString()) {
+ div(classes = "table-row") {
+ it.filterIsInstance<ContentLink>().takeIf { it.isNotEmpty() }?.let {
+ div("main-subrow " + node.style.joinToString(" ")) {
+ it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
+ .forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1))
+ createPlatformTags(node)
+ }
+ }
}
- }
- it.filter { it !is ContentLink }.takeIf { it.isNotEmpty() }?.let {
- div("platform-dependent-row keyValue") {
- val title = it.filter { it.style.contains(ContentStyle.RowTitle) }
- div {
- title.forEach {
- it.build(this, pageContext, sourceSetRestriction)
+ it.filter { it !is ContentLink }.takeIf { it.isNotEmpty() }?.let {
+ div("platform-dependent-row keyValue") {
+ val title = it.filter { it.style.contains(ContentStyle.RowTitle) }
+ div {
+ title.forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ }
}
- }
- div("title") {
- (it - title).forEach {
- it.build(this, pageContext, sourceSetRestriction)
+ div("title") {
+ (it - title).forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ }
}
}
}
@@ -255,17 +257,26 @@ open class HtmlRenderer(
}
- override fun FlowContent.buildHeader(level: Int, content: FlowContent.() -> Unit) {
+ override fun FlowContent.buildHeader(level: Int, node: ContentHeader, content: FlowContent.() -> Unit) {
+ val anchor = node.extra[SimpleAttr.SimpleAttrKey("anchor")]?.extraValue
when (level) {
- 1 -> h1(block = content)
- 2 -> h2(block = content)
- 3 -> h3(block = content)
- 4 -> h4(block = content)
- 5 -> h5(block = content)
- else -> h6(block = content)
+ 1 -> h1() { withAnchor(anchor, content) }
+ 2 -> h2() { withAnchor(anchor, content) }
+ 3 -> h3() { withAnchor(anchor, content) }
+ 4 -> h4() { withAnchor(anchor, content) }
+ 5 -> h5() { withAnchor(anchor, content) }
+ else -> h6() { withAnchor(anchor, content) }
}
}
+ private fun FlowContent.withAnchor(anchorName: String?, content: FlowContent.() -> Unit) {
+ a {
+ anchorName?.let { attributes["name"] = it }
+ }
+ content()
+ }
+
+
override fun FlowContent.buildNavigation(page: PageNode) =
div(classes = "breadcrumbs") {
locationProvider.ancestors(page).asReversed().forEach { node ->
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 c7b65aa9..c0b8233c 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -60,7 +60,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
node.dri.first(),
node.documentable!!.sourceSets.toSet()
) {
- header(2) { text("Sources") }
+ header(2, "Sources")
+ContentTable(
emptyList(),
sources.map {
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index 296b0de6..d4ee88d8 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -65,7 +65,7 @@ open class DefaultPageCreator(
protected open fun contentForModule(m: DModule) = contentBuilder.contentFor(m) {
group(kind = ContentKind.Cover) {
- header(1) { text(m.name) }
+ header(1, m.name)
}
+contentForComments(m)
block("Packages", 2, ContentKind.Packages, m.packages, m.sourceSets.toSet()) {
@@ -77,7 +77,7 @@ open class DefaultPageCreator(
protected open fun contentForPackage(p: DPackage) = contentBuilder.contentFor(p) {
group(kind = ContentKind.Cover) {
- header(1) { text("Package ${p.name}") }
+ header(1, "Package ${p.name}")
}
+contentForComments(p)
+contentForScope(p, p.dri, p.sourceSets)
@@ -108,7 +108,7 @@ open class DefaultPageCreator(
s.safeAs<WithExtraProperties<Documentable>>()?.let { it.extra[InheritorsInfo] }?.let { inheritors ->
val map = inheritors.value.filter { it.value.isNotEmpty() }
if (map.values.any()) {
- header(2) { text("Inheritors") }
+ header(2, "Inheritors") { }
+ContentTable(
emptyList(),
map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } }
@@ -130,7 +130,7 @@ open class DefaultPageCreator(
protected open fun contentForEnumEntry(e: DEnumEntry) = contentBuilder.contentFor(e) {
group(kind = ContentKind.Cover) {
- header(1) { text(e.name) }
+ header(1, e.name)
+buildSignature(e)
}
+contentForComments(e)
@@ -139,8 +139,8 @@ open class DefaultPageCreator(
protected open fun contentForClasslike(c: DClasslike) = contentBuilder.contentFor(c) {
group(kind = ContentKind.Cover) {
- header(1) { text(c.name.orEmpty()) }
- sourceSetDependentHint(c.dri, c.sourceSets.toSet()) {
+ header(1, c.name.orEmpty())
+ sourceSetDependentHint(c.dri, c.sourceSets.toSet()) {
+buildSignature(c)
}
}
@@ -215,7 +215,7 @@ open class DefaultPageCreator(
val receiver = tags.withTypeUnnamed<Receiver>()
val params = tags.withTypeNamed<Param>()
platforms.forEach {
- header(4, kind = ContentKind.Parameters, platformData = setOf(it)) { text("Parameters") }
+ header(4, "Parameters", kind = ContentKind.Parameters, platformData = setOf(it))
}
table(kind = ContentKind.Parameters) {
platforms.flatMap { platform ->
@@ -245,7 +245,7 @@ open class DefaultPageCreator(
if (tags.isNotEmptyForTag<See>()) {
val seeAlsoTags = tags.withTypeNamed<See>()
platforms.forEach {
- header(4, kind = ContentKind.Comment, platformData = setOf(it)) { text("See also") }
+ header(4, "See also", kind = ContentKind.Comment, platformData = setOf(it))
}
table(kind = ContentKind.Sample) {
platforms.flatMap { platform ->
@@ -270,7 +270,7 @@ open class DefaultPageCreator(
val content = samples.filter { it.value.isEmpty() || platformData in it.value }
if (content.isNotEmpty()) {
group(sourceSets = setOf(platformData)) {
- header(4, kind = ContentKind.Comment) { text("Samples") }
+ header(4, "Samples", kind = ContentKind.Comment)
content.forEach {
comment(Text(it.key))
}
@@ -288,7 +288,7 @@ open class DefaultPageCreator(
unnamedTags.forEach { pdTag ->
pdTag[platform]?.also { tag ->
group(sourceSets = setOf(platform)) {
- header(4) { text(tag.toHeaderString()) }
+ header(4, tag.toHeaderString())
comment(tag.root)
}
}
@@ -298,7 +298,7 @@ open class DefaultPageCreator(
return contentBuilder.contentFor(d) {
if (tags.isNotEmpty()) {
- header(3) { text("Description") }
+ header(3, "Description")
sourceSetDependentHint(sourceSets = platforms.toSet()) {
contentForDescription()
contentForSamples()
@@ -323,7 +323,7 @@ open class DefaultPageCreator(
protected open fun contentForFunction(f: DFunction) = contentForMember(f)
protected open fun contentForTypeAlias(t: DTypeAlias) = contentForMember(t)
protected open fun contentForMember(d: Documentable) = contentBuilder.contentFor(d) {
- header(1) { text(d.name.orEmpty()) }
+ header(1, d.name.orEmpty())
divergentGroup(ContentDivergentGroup.GroupID("member")) {
instance(setOf(d.dri), d.sourceSets.toSet()) {
divergent(kind = ContentKind.Symbol) {
@@ -342,7 +342,7 @@ open class DefaultPageCreator(
kind: ContentKind
) {
if (collection.any()) {
- header(2) { text(name) }
+ header(2, name)
table(kind) {
collection.groupBy { it.name }.map { (elementName, elements) -> // This groupBy should probably use LocationProvider
buildGroup(elements.map { it.dri }.toSet(), elements.flatMap { it.sourceSets }.toSet(), kind = kind) {
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 9c80a9ea..658a86f2 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -85,15 +85,25 @@ open class PageContentBuilder(
fun header(
level: Int,
+ text: String,
kind: Kind = ContentKind.Main,
platformData: Set<SourceSetData> = mainPlatformData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
- block: DocumentableContentBuilder.() -> Unit
+ block: DocumentableContentBuilder.() -> Unit = {}
) {
contents += ContentHeader(
level,
- contentFor(mainDRI, platformData, kind, styles, extra, block)
+ contentFor(
+ mainDRI,
+ platformData,
+ kind,
+ styles,
+ extra + SimpleAttr("anchor", text.replace("\\s".toRegex(), "").toLowerCase())
+ ){
+ text(text)
+ block()
+ }
)
}
@@ -155,7 +165,7 @@ open class PageContentBuilder(
operation: DocumentableContentBuilder.(T) -> Unit
) {
if (renderWhenEmpty || elements.any()) {
- header(level) { text(name) }
+ header(level, name) { }
contents += ContentTable(
emptyList(),
elements.map {