diff --git a/docs/example/example-core/src/commonMain/kotlin/Example.kt b/docs/example/example-core/src/commonMain/kotlin/Example.kt index c9da3c9..660c918 100644 --- a/docs/example/example-core/src/commonMain/kotlin/Example.kt +++ b/docs/example/example-core/src/commonMain/kotlin/Example.kt @@ -74,6 +74,19 @@ fun topLevelFunction(): Int { TODO() } +/** + * This is another top-level function with multiple parameters. + */ +fun anotherTopLevelFunction( + param1: String, + param2: Int, + param3: Boolean, + param4: String = "default", + onAction: () -> Unit +): Int { + TODO() +} + /** * This is a typealias. * diff --git a/renderer/src/main/kotlin/MaterialForMkDocsPlugin.kt b/renderer/src/main/kotlin/MaterialForMkDocsPlugin.kt index 16162b0..18815b1 100644 --- a/renderer/src/main/kotlin/MaterialForMkDocsPlugin.kt +++ b/renderer/src/main/kotlin/MaterialForMkDocsPlugin.kt @@ -18,6 +18,7 @@ package opensavvy.dokka.material.mkdocs import opensavvy.dokka.material.mkdocs.location.MarkdownLocationProvider import opensavvy.dokka.material.mkdocs.renderer.BriefCommentPreprocessor +import opensavvy.dokka.material.mkdocs.renderer.SignatureBreaklineTransformer import opensavvy.dokka.material.mkdocs.renderer3.MkDocsRenderer3 import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase @@ -52,6 +53,10 @@ class MaterialForMkDocsPlugin : DokkaPlugin() { mkdocsPreprocessor with BriefCommentPreprocessor() } + val signatureBreaklineTransformer: Extension by extending { + mkdocsPreprocessor with SignatureBreaklineTransformer() + } + val packageListCreator: Extension by extending { (mkdocsPreprocessor providing { PackageListCreator(it, RecognizedLinkFormat.DokkaGFM) } diff --git a/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt b/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt new file mode 100644 index 0000000..a79e26a --- /dev/null +++ b/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.dokka.material.mkdocs.renderer + +import opensavvy.dokka.material.mkdocs.renderer3.MultilineSignatureStyle +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.transformers.pages.PageTransformer + +private const val MIN_PARAMS_FOR_MULTILINE = 3 +private const val MAX_LINE_LENGTH = 80 + +class SignatureBreaklineTransformer : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode = + input.transformContentPagesTree { page -> + page.modified( + content = page.content.recursiveMapTransform { + if (it.dci.kind == SymbolContentKind.Parameters && shouldWrapParams(it)) { + it.copy( + style = it.style + MultilineSignatureStyle.Wrapped, + children = it.children.map { child -> + (child as? ContentGroup) + ?.copy(style = child.style + MultilineSignatureStyle.Indented) + ?: child + } + ) + } else { + it + } + } + ) + } + + private fun shouldWrapParams(group: ContentGroup): Boolean { + val paramCount = group.children.count { + (it as? ContentGroup)?.dci?.kind == SymbolContentKind.Parameter + } + return paramCount >= MIN_PARAMS_FOR_MULTILINE || + group.plainTextLength() > MAX_LINE_LENGTH + } + + private fun ContentNode.plainTextLength(): Int = when (this) { + is ContentText -> text.length + is ContentGroup -> children.sumOf { it.plainTextLength() } + else -> 0 + } +} diff --git a/renderer/src/main/kotlin/renderer3/Groups.kt b/renderer/src/main/kotlin/renderer3/Groups.kt index 8b12fe3..c0f5e78 100644 --- a/renderer/src/main/kotlin/renderer3/Groups.kt +++ b/renderer/src/main/kotlin/renderer3/Groups.kt @@ -17,9 +17,10 @@ package opensavvy.dokka.material.mkdocs.renderer3 import org.jetbrains.dokka.pages.ContentComposite +import org.jetbrains.dokka.pages.Style import org.jetbrains.dokka.pages.TextStyle -private val groupStyles = mapOf( +private val groupStyles: Map = mapOf( TextStyle.Monospace to Decorator { content -> if (!this.isInCodeBlock) append("
")
@@ -40,6 +41,15 @@ private val groupStyles = mapOf(
 		content()
 		appendLine()
 		appendLine("")
+	},
+	MultilineSignatureStyle.Wrapped to Decorator { content ->
+		content()
+		appendLine()
+	},
+	MultilineSignatureStyle.Indented to Decorator { content ->
+		appendLine()
+		append("    ")
+		content()
 	}
 )
 
diff --git a/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt b/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt
new file mode 100644
index 0000000..8b71bbf
--- /dev/null
+++ b/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2025, OpenSavvy and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package opensavvy.dokka.material.mkdocs.renderer3
+
+import org.jetbrains.dokka.pages.Style
+
+internal enum class MultilineSignatureStyle : Style {
+    Wrapped,
+    Indented,
+}
-- 
2.51.2


From 67f6885f87652f1f6d4411d3130497fbaea64087 Mon Sep 17 00:00:00 2001
From: t-regbs 
Date: Mon, 23 Feb 2026 09:28:15 +0000
Subject: [PATCH 2/2] chore: update copyright year to 2026 in signature style
 and transformer files

---
 .../src/main/kotlin/renderer/SignatureBreaklineTransformer.kt   | 2 +-
 renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt b/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt
index a79e26a..c81b379 100644
--- a/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt
+++ b/renderer/src/main/kotlin/renderer/SignatureBreaklineTransformer.kt
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2025, OpenSavvy and contributors.
+ * Copyright (c) 2026, OpenSavvy and contributors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt b/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt
index 8b71bbf..508ad54 100644
--- a/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt
+++ b/renderer/src/main/kotlin/renderer3/MultilineSignatureStyle.kt
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2025, OpenSavvy and contributors.
+ * Copyright (c) 2026, OpenSavvy and contributors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.