kotlinx-knit
kotlinx-knit copied to clipboard
Knit creates invalid TOC links when text contains quotation mark `"`
Given some markdown
#### Using `JsonUnquotedLiteral` to encode `"null"` is forbidden
To avoid creating an inconsistent state, encoding a String equal to `"null"` is forbidden.
Use [JsonNull] or [JsonPrimitive] instead.
Knit generates an invalid link
* [Using `JsonUnquotedLiteral` to encode `"null"` is forbidden](#using-jsonunquotedliteral-to-encode-"null"-is-forbidden)

If I change the link to remove the quotation marks, then it works as expected.
* [Using `JsonUnquotedLiteral` to encode `"null"` is forbidden](#using-jsonunquotedliteral-to-encode-null-is-forbidden)
I found this comment, https://gist.github.com/asabaylus/3071099?permalink_comment_id=1593627#gistcomment-1593627
The code that creates the anchors is here: https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
- It downcases the string
- remove anything that is not a letter, number, space or hyphen (see the source for how Unicode is handled)
- changes any space to a hyphen.
- If that is not unique, add "-1", "-2", "-3",... to make it unique
It's from 2015, so this might be outdated. Perhaps this logic can be used to make the link handling more robust.
See also: https://github.com/imthenachoman/nGitHubTOC