aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt4
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt4
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt4
5 files changed, 14 insertions, 10 deletions
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index 6ac2a405..ebc4ce22 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -27,9 +27,9 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
return "<span class=\"identifier\"$id>${formatText(text)}</span>"
}
- override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ override fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String) {
to.append("<pre><code>")
- to.append(line)
+ to.append(lines.joinToString("\n"))
to.append("</code></pre>")
}
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index 9a739216..56544165 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -107,12 +107,12 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe
to.appendln("\n</td>")
}
- override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ override fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String) {
if (language.isNotEmpty()) {
- super.appendBlockCode(to, line, language)
+ super.appendBlockCode(to, lines, language)
} else {
to.append("<pre markdown=\"1\">")
- to.append(line.trimStart())
+ to.append(lines.joinToString { "\n" }.trimStart())
to.append("</pre>")
}
}
diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
index 4f5b9751..21470141 100644
--- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt
+++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
@@ -67,10 +67,10 @@ open class MarkdownFormatService(locationService: LocationService,
appendLine(to)
}
- override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ override fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String) {
appendLine(to)
- to.appendln("``` ${language}")
- to.appendln(line)
+ to.appendln(if (language.isEmpty()) "```" else "``` $language")
+ to.appendln(lines.joinToString("\n"))
to.appendln("```")
appendLine(to)
}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 85b7d3c1..15a4dfba 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -16,7 +16,7 @@ abstract class StructuredFormatService(locationService: LocationService,
val linkExtension: String = extension) : FormatService {
val locationService: LocationService = locationService.withExtension(linkExtension)
- abstract fun appendBlockCode(to: StringBuilder, line: String, language: String)
+ abstract fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String)
abstract fun appendHeader(to: StringBuilder, text: String, level: Int = 1)
abstract fun appendParagraph(to: StringBuilder, text: String)
abstract fun appendLine(to: StringBuilder, text: String = "")
@@ -92,7 +92,7 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
is ContentParagraph -> appendParagraph(to, formatText(location, content.children))
- is ContentBlockCode -> appendBlockCode(to, formatText(location, content.children), content.language)
+ is ContentBlockCode -> appendBlockCode(to, content.children.map { formatText(location, it) }, content.language)
is ContentHeading -> appendHeader(to, formatText(location, content.children), content.level)
is ContentBlock -> to.append(formatText(location, content.children))
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 15be6c77..508790b1 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -246,6 +246,10 @@ class MarkdownFormatTest {
verifyMarkdownNode("jdkLinks", withKotlinRuntime = true)
}
+ @Test fun codeBlock() {
+ verifyMarkdownNode("codeBlock")
+ }
+
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
markdownService.appendNodes(tempLocation, output, model.members)