Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support code blocks and inline code for GFM format (#2485)
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) ```
- Loading branch information
1 parent
6046abc
commit 3fb60bc
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugins/gfm/src/test/kotlin/renderers/gfm/CodeWrappingTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package renderers.gfm | ||
|
||
import org.jetbrains.dokka.gfm.renderer.CommonmarkRenderer | ||
import org.jetbrains.dokka.pages.TextStyle | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
import renderers.* | ||
|
||
class CodeWrappingTest : GfmRenderingOnlyTestBase() { | ||
@Test | ||
fun wrappedCodeBlock() { | ||
val page = testPage { | ||
codeBlock { | ||
text("fun myCode(): String") | ||
} | ||
} | ||
val expect = """|//[testPage](test-page.md) | ||
| | ||
|```kotlin | ||
|fun myCode(): String | ||
|```""".trimMargin() | ||
|
||
CommonmarkRenderer(context).render(page) | ||
assertEquals(expect, renderedContent) | ||
} | ||
|
||
@Test | ||
fun wrappedInlineCode() { | ||
val page = testPage { | ||
text("This function adds the values of ") | ||
codeInline("") { | ||
text("left") | ||
} | ||
text(" and ") | ||
codeInline("") { | ||
text("right") | ||
} | ||
text(".\nBoth numbers must be finite, or an exception occurs.\n") | ||
} | ||
val expect = """|//[testPage](test-page.md) | ||
| | ||
|This function adds the values of `left` and `right`. | ||
|Both numbers must be finite, or an exception occurs.""".trimMargin() | ||
|
||
CommonmarkRenderer(context).render(page) | ||
assertEquals(expect, renderedContent) | ||
} | ||
} |