Consecutive links and codes not properly handled
When links and inline code sections appear back-by-back, some of the links and codes are simply not recognized.
Example:
/**
* `a`[Int]`b`[Long]`c`
*/
fun main() {}
Expected: Dokka generates the description as:
<code>a</code>
<a href="kotlin.Int">Int</a>
<code>b</code>
<a href="kotlin.Long">Long</a>
<code>c</code>
Note: This is strawman HTML, not exactly what Dokka will generate.
Actual: Dokka generates the description as:
<p class="paragraph">
<code class="lang-kotlin">a</code>
<a href="https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html">Int</a>
<code class="lang-kotlin">c</code>
</p>
Notice the Int linking to kotlin.Long.
Screenshot of the generated documentation of main:
The link Int redirects to https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long.
Also tested in K2, results in no difference.
Debugging into Dokka using a DocumentableTransformer shows: (Click to zoom in)
The innermost
children shows only 3 elements, and the middle one reads Int and links to kotlin.Long.
These back-to-back links and codes were to replicate how Intellij IDEA renders it pretty, as a workaround for #3571:
Though it is still not right, and the
Int here also redirects to kotlin.Long.
Installation
- Operating system: Windows 11
- Build tool: Gradle v8.14.3
- Dokka version: 2.0.0 with V2 enabled
Intellij IDEA, if you need:
IntelliJ IDEA 2025.1.4.1 (Community Edition) Build #IC-251.27812.49, built on July 25, 2025 Source revision: 735cc3bd3c92f Runtime version: 21.0.7+9-b895.130 amd64 (JCEF 122.1.9) VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.awt.windows.WToolkit Windows 11.0 Kotlin plugin: K2 mode Kotlin analyzer version: 2.2.0-ij251-153 GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation Memory: 2952M Cores: 16 Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true llm.show.ai.promotion.window.on.start=false kotlin.scripting.index.dependencies.sources=true terminal.new.ui.reworked=true Non-Bundled Plugins: dev.azn9.plugins.discord (2.1.7.242) Kotlin: 251.27812.49-IJ
Edit: Changed actual result to the HTML that Dokka actually generates, not what the browser shows
Thanks for the reproducer! This is actually an issue in the KDoc parser. That's why the behavior is the same in both IDEA and Dokka. I've created an issue "KT-80659 Consecutive links and code-blocks not properly handled". Feel free to follow it.
Related issues:
- KTIJ-35278 KDoc unlabeled element link is broken if followed by a labeled link
- KTIJ-35552 KDoc parser: Consecutive links and code-blocks not properly handled
Most likely the issue is in https://github.com/JetBrains/markdown
I've created a (temporary) fix for this: jetbrains/markdown#177 @whyoleg can you(or make someone else) have a look at it?
@spacedvoid, thanks! Let's see what I can do :)