New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dokkaHtml preserves teletype formatting, but dokkaGfm unhelpfully strips it #2477
Comments
Low hanging fruit. Functions that render code blocks need to be overriden in CommonmarkRenderer: override fun StringBuilder.buildCodeBlock(code: ContentCodeBlock, pageContext: ContentPage) {
TODO("Not yet implemented")
}
override fun StringBuilder.buildCodeInline(code: ContentCodeInline, pageContext: ContentPage) {
TODO("Not yet implemented")
} |
@IgnatBeresnev, if I provide a pull request to fix this issue, is that something you would consider accepting? (Assuming of course that you approve the fix.) |
@cosinekitty yeah, sure, I'd be happy to review it! I've had a look and there's only one difficult part that I missed -- you'll need it for tests. Add the following code to fun codeBlock(
language: String = "",
kind: Kind = ContentKind.Main,
sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit
) {
contents += ContentCodeBlock(
contentFor(mainDRI, sourceSets, kind, styles, extra, block).children,
language,
DCI(mainDRI, kind),
sourceSets.toDisplaySourceSets(),
styles,
extra
)
}
fun codeInline(
language: String,
kind: Kind = ContentKind.Main,
sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit
) {
contents += ContentCodeInline(
contentFor(mainDRI, sourceSets, kind, styles, extra, block).children,
language,
DCI(mainDRI, kind),
sourceSets.toDisplaySourceSets(),
styles,
extra
)
} You will have to run For test examples, see class CodeWrappingTest : GfmRenderingOnlyTestBase() {
@Test
fun testCodeWrapping() {
val page = testPage {
codeBlock {
text("fun myCode(): String")
}
}
val expect = """|//[testPage](test-page.md)
|
|```
|fun myCode(): String
|```""".trimMargin()
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
} I'll leave the rest (spec, corner cases, tests) to you, that's by far the most difficult part :) For help, see CONTRIBUTING.md (it's rather poor, but better than nothing), and feel free to reach out to me in Kotlin's community slack (you can find me by my messages in |
Thank you for all the info! I will give it a shot over the next week or so. |
I'm making some progress, but I have a basic question about the classes |
Nice hearing from you, I'm glad you haven't given up :)
I think you are correct in the majority of cases as it will indeed be a single text node. However, because Dokka is pluggable and the content model is universal (meaning it's the same both for commonmark and html renderers), I can imagine a scenario in which content inside For instance, there might be multiple nodes that wrap text with some code highlighting or other styles, or there could even be a feature/plugin that generates clickable links for functions/classes used inside code blocks (interactive examples, if you will), or something like that. Not aware of any such examples atm, but could definitely happen.
So to be on the safe side, I would just build all children. If there's only one text node, it'll should be built just fine. The rest is up to other rendering functions to implement other content types :) (pseudo code)
text("```")
newLine()
code.children.forEach { it.build(this, pageContext) }
newLine()
text("```") |
That helped a lot, thank you! I think I am close. |
Fixes #2477. Inline code, text that is nested within a pair of backquotes, is now converted into GitHub Flavored Markdown (gfm) without stripping out the backquotes. For example: The parameter `sum` must be a non-negative real number. Code blocks, which are any number of lines of literal text between triple-backquotes, and an optional programming language name, are now preserved. If absent, the programming language is assumed to be "kotlin". This follows the behavior of the html renderer. For example: Here is an example of calling the function: ```kotlin val sum = addThemUp(left, right) ```
Describe the bug
In my Kotlin comments, I often refer to a parameter name or other code symbol using backquotes, as is typical in Markdown to render teletype/monospace text. For example, my remarks about
eclipticSeparation
in:dokkaHtml respects this notation and converts this into
This is the desired behavior. However, dokkaGfm strips out the backquotes and converts into plain text:
- eclipticSeparation is the absolute value of ...
Expected behaviour
Backquotes should be left intact in dokkaGfm's markdown output, so that it is clear which parts of the text are prose, and which are source code excerpts. For example:
Screenshots
N/A
To Reproduce
git checkout -b backquote 53f5540f09df94baae112c56b9fb5066175d8a0f
cd source/kotlin
./gradlew dokkaGfm dokkaHtml
source/kotlin/build/dokka/gfm/astronomy/io.github.cosinekitty.astronomy/elongation.md
. Notice that the backquotes have been removed from the documented symbols "visibility", "elongation", and "eclipticSeparation".source/kotlin/build/dokka/html/astronomy/io.github.cosinekitty.astronomy/-astronomy/elongation.html
. This suggests the bug is specific to dokkaGfm.Dokka configuration
(See repro steps above. The configuration is present in the directory
source/kotlin
.)Installation
Additional context
Are you willing to provide a PR?
I am happy to provide whatever help the maintainers could use to reproduce/diagnose this bug. Thank you!
The text was updated successfully, but these errors were encountered: