aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/translators
diff options
context:
space:
mode:
authorDon Cross <cosinekitty@users.noreply.github.com>2022-05-04 12:33:21 -0400
committerGitHub <noreply@github.com>2022-05-04 19:33:21 +0300
commit3fb60bc74a4ed4e4c795f2f14fa112321a3c94cc (patch)
tree8ca1c8f5147a1a15fa577898594d496a2f330c83 /plugins/base/src/main/kotlin/translators
parent6046abccab85f2cfde5e20476d3b9ea1b1ab1ff9 (diff)
downloaddokka-3fb60bc74a4ed4e4c795f2f14fa112321a3c94cc.tar.gz
dokka-3fb60bc74a4ed4e4c795f2f14fa112321a3c94cc.tar.bz2
dokka-3fb60bc74a4ed4e4c795f2f14fa112321a3c94cc.zip
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) ```
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt36
1 files changed, 36 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 7b6fbc7a..363b6a3f 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -363,6 +363,42 @@ open class PageContentBuilder(
contents += ContentGroup(content, DCI(mainDRI, kind), sourceSets.toDisplaySourceSets(), styles, extra)
}
+ 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
+ )
+ }
+
fun firstParagraphComment(
content: DocTag,
kind: Kind = ContentKind.Comment,