aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-07-27 18:53:23 +0200
committerGitHub <noreply@github.com>2022-07-27 18:53:23 +0200
commit26dde5b201b3c7e66212b07ddef333a3e340022a (patch)
tree7a63a244bcf2d9a8b0a031b9b7d82395634ba7fa /plugins
parentf4d2bf40e7b7e62aeb27bf0f1cabe53e35e68fd2 (diff)
downloaddokka-26dde5b201b3c7e66212b07ddef333a3e340022a.tar.gz
dokka-26dde5b201b3c7e66212b07ddef333a3e340022a.tar.bz2
dokka-26dde5b201b3c7e66212b07ddef333a3e340022a.zip
Make current breadcrumb element not clickable and of default font color (#2588)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt14
-rw-r--r--plugins/base/src/main/resources/dokka/styles/style.css4
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/BreadcrumbsTest.kt84
3 files changed, 100 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 30ae0562..9f568287 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -634,8 +634,18 @@ open class HtmlRenderer(
}
private fun FlowContent.buildNavigationElement(node: PageNode, page: PageNode) =
- if (node.isNavigable) buildLink(node, page)
- else text(node.name)
+ if (node.isNavigable) {
+ val isCurrentPage = (node == page)
+ if (isCurrentPage) {
+ span(classes = "current") {
+ text(node.name)
+ }
+ } else {
+ buildLink(node, page)
+ }
+ } else {
+ text(node.name)
+ }
private fun FlowContent.buildLink(to: PageNode, from: PageNode) =
locationProvider.resolve(to, from)?.let { path ->
diff --git a/plugins/base/src/main/resources/dokka/styles/style.css b/plugins/base/src/main/resources/dokka/styles/style.css
index ad8569ea..e32ec063 100644
--- a/plugins/base/src/main/resources/dokka/styles/style.css
+++ b/plugins/base/src/main/resources/dokka/styles/style.css
@@ -150,6 +150,10 @@ html ::-webkit-scrollbar-thumb {
margin: auto 2px;
}
+.breadcrumbs .current {
+ color: var(--default-font-color);
+}
+
.tabs-section > .section-tab:first-child,
.platform-hinted > .platform-bookmarks-row > .platform-bookmark:first-child {
margin-left: 0;
diff --git a/plugins/base/src/test/kotlin/renderers/html/BreadcrumbsTest.kt b/plugins/base/src/test/kotlin/renderers/html/BreadcrumbsTest.kt
new file mode 100644
index 00000000..bebc41dc
--- /dev/null
+++ b/plugins/base/src/test/kotlin/renderers/html/BreadcrumbsTest.kt
@@ -0,0 +1,84 @@
+package renderers.html
+
+import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.jsoup.nodes.Element
+import org.junit.jupiter.api.Test
+import signatures.renderedContent
+import utils.*
+
+class BreadcrumbsTest : BaseAbstractTest() {
+
+ private val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ }
+ }
+ }
+
+ @Test
+ fun `should add breadcrumbs with current element`() {
+ val writerPlugin = TestOutputWriterPlugin()
+ testInline(
+ """
+ |/src/main/kotlin/basic/TestClass.kt
+ |package testpackage
+ |
+ |class TestClass {
+ | fun foo() {}
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/testpackage/-test-class/foo.html").selectBreadcrumbs().match(
+ link("root"),
+ delimiter(),
+ link("testpackage"),
+ delimiter(),
+ link("TestClass"),
+ delimiter(),
+ current("foo"),
+ ignoreSpanWithTokenStyle = true
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `should mark only one element as current even if more elements have the same name`() {
+ val writerPlugin = TestOutputWriterPlugin()
+ testInline(
+ """
+ |/src/main/kotlin/basic/TestClass.kt
+ |package testpackage
+ |
+ |class testname {
+ | val testname: String = ""
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/testpackage/testname/testname.html").selectBreadcrumbs().match(
+ link("root"),
+ delimiter(),
+ link("testpackage"),
+ delimiter(),
+ link("testname"),
+ delimiter(),
+ current("testname"),
+ ignoreSpanWithTokenStyle = true
+ )
+ }
+ }
+ }
+
+ private fun Element.selectBreadcrumbs() = this.select("div.breadcrumbs").single()
+
+ private fun link(text: String): Tag = A(text)
+ private fun delimiter(): Tag = Span().withClasses("delimiter")
+ private fun current(text: String): Tag = Span(text).withClasses("current")
+}