aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Formats
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/Formats')
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt9
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt12
2 files changed, 13 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index edae9976..ac70bb02 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -53,9 +53,14 @@ class KotlinWebsiteOutputBuilder(to: StringBuilder,
}
}
- override fun appendSampleBlockCode(language: String, body: () -> Unit) {
+ override fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) {
div(to, "sample", true) {
- appendBlockCode(language, body)
+ appendBlockCode(language) {
+ imports()
+ wrap("\nfun main(args: Array<String>) {", "}") {
+ wrap("\n//sampleStart\n", "\n//sampleEnd\n", body)
+ }
+ }
}
}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 3bd06130..183282ea 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -47,7 +47,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
protected abstract fun ensureParagraph()
- open fun appendSampleBlockCode(language: String, body: () -> Unit) = appendBlockCode(language, body)
+ open fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) = appendBlockCode(language, body)
abstract fun appendBlockCode(language: String, body: () -> Unit)
abstract fun appendHeader(level: Int = 1, body: () -> Unit)
abstract fun appendParagraph(body: () -> Unit)
@@ -146,19 +146,19 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
is ContentBlockSampleCode, is ContentBlockCode -> {
content as ContentBlockCode
- fun appendBlockCodeContent() {
- for ((index, contentNode) in content.children.withIndex()) {
+ fun ContentBlockCode.appendBlockCodeContent() {
+ for ((index, contentNode) in this.children.withIndex()) {
appendContent(contentNode)
- if (index < content.children.size - 1) {
+ if (index < this.children.size - 1) {
to.append("\n")
}
}
}
when (content) {
is ContentBlockSampleCode ->
- appendSampleBlockCode(content.language, ::appendBlockCodeContent)
+ appendSampleBlockCode(content.language, content.importsBlock::appendBlockCodeContent, { content.appendBlockCodeContent() })
is ContentBlockCode ->
- appendBlockCode(content.language, ::appendBlockCodeContent)
+ appendBlockCode(content.language, { content.appendBlockCodeContent() })
}
}
is ContentHeading -> appendHeader(content.level) { appendContent(content.children) }