Skip to content
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

Fix for incorrect rendering of deprecated code #2181

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -213,10 +213,11 @@ open class CommonmarkRenderer(
append(textNode.text)
} else if (textNode.text.isNotBlank()) {
val decorators = decorators(textNode.style)
val containsStrikethrough = textNode.style.contains(TextStyle.Strikethrough)
append(textNode.text.takeWhile { it == ' ' })
append(decorators)
if (containsStrikethrough) append("<s>") else append(decorators)
append(textNode.text.trim().htmlEscape())
append(decorators.reversed())
if (containsStrikethrough) append("</s>") else append(decorators.reversed())
append(textNode.text.takeLastWhile { it == ' ' })
}
}
Expand Down
54 changes: 54 additions & 0 deletions plugins/gfm/src/test/kotlin/renderers/gfm/ParseRenderTest.kt
@@ -0,0 +1,54 @@
package renderers.gfm

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.gfm.GfmPlugin
import org.junit.Assert.assertEquals
import org.junit.jupiter.api.Test
import utils.TestOutputWriterPlugin

class ParseRenderTest : BaseAbstractTest() {

@Test
fun `deprecated fun markdown`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/main/kotlin/test/Test.kt")
}
}
}
val source =
"""
|/src/main/kotlin/test/Test.kt
|package example
| /**
| * Just a deprecated function
| */
| @Deprecated("This is deprecated")
| fun simpleFun(test: Int): String = "This is the one ring"
""".trimIndent()
val expected =
"""
//[root](../../index.md)/[example](index.md)

# Package example

## Functions

| Name | Summary |
|---|---|
| [simpleFun](simple-fun.md) | [JVM]<br><s>fun</s> [<s>simpleFun</s>](simple-fun.md)<s>(</s><s>test</s><s>:</s> Int<s>)</s><s>:</s> String<br>Just a deprecated function |
""".trimIndent()
val writerPlugin = TestOutputWriterPlugin()

testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin, GfmPlugin())
) {
renderingStage = { _, _ ->
assertEquals(expected, writerPlugin.writer.contents["root/example/index.md"])
}
}
}
}
Expand Up @@ -78,7 +78,7 @@ class SimpleElementsTest : GfmRenderingOnlyTestBase() {
)
}
val expect =
"//[testPage](test-page.md)\n\n~~A day may come when the courage of men fails… but it is not THIS day~~"
"//[testPage](test-page.md)\n\n<s>A day may come when the courage of men fails… but it is not THIS day</s>"
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
Expand Down