dokka icon indicating copy to clipboard operation
dokka copied to clipboard

GFM links to function parameters are invalid

Open drmoose opened this issue 6 years ago • 3 comments

Given the following sample code:

package com.example

/**
 * I will now link to my [parameter] for fun and profit!
 *
 * @param parameter Here is my parameter documentation.
 */
fun someFunction(parameter: String, secondParam: Double) {
}

and the command line:

java -jar dokka-fatjar.jar src/main -format gfm

Dokka 0.9.15 renders the following markdown:

[com.example](index.md) / [someFunction](.)

# someFunction

`fun someFunction(parameter: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, secondParam: `[`Double`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)

I will now link to my [parameter](some-function.md#com.example$someFunction(kotlin.String, kotlin.Double)/parameter) for fun and profit!

### Parameters

`parameter` - Here is my parameter documentation.

The link to parameter is invalid (it should be some-function.md#parameters, as that is the most specific link possible given markdown's id=""-generating rules.), and because it includes spaces, commas, and nested parens, breaks some markdown parsers. Github itself just ignores it:

[parameter](some-function.md#com.example$someFunction(kotlin.String, kotlin.Double)/parameter)

mkdocs renders it as

<a href="index.html#com.example$someFunction(kotlin.String">parameter</a>, kotlin.Double)/parameter)

One work-around for the problem is to add some regex filters to postprocess the href parameter passed to MarkdownOutputBuilder's appendLink, but as a solution that feels ugly and brittle, and in particular seems likely to accidentally break links to external docs.

drmoose avatar Oct 14 '17 14:10 drmoose

Anchor link should be URL encoded

semoro avatar May 22 '18 12:05 semoro

This is about old gfm, but the issue is probably still present in the new format.

Kordyjan avatar Aug 31 '20 12:08 Kordyjan

Indeed, still relevant for the new gfm format (~1.6.20), but the behaviour is somewhat different (still not what's expected):

//[Dokka Debug KTS](../../index.md)/[me.beresnev.dokka.debug](index.md)/[someFunction](some-function.md)

# someFunction

[jvm]\
fun [someFunction](some-function.md)(parameter: [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html), secondParam: [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html))

I will now link to my [parameter](some-function.md) for fun and profit!

## Parameters

jvm

| | |
|---|---|
| parameter | Here is my parameter documentation. |

IgnatBeresnev avatar Apr 27 '22 16:04 IgnatBeresnev