From 792ae5c4099c7a37815888cd1313404375453eea Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 31 Mar 2016 21:04:27 +0200 Subject: Don't lose line breaks in code blocks. Resolves #54 --- core/src/main/kotlin/Formats/HtmlFormatService.kt | 4 ++-- core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt | 6 +++--- core/src/main/kotlin/Formats/MarkdownFormatService.kt | 6 +++--- core/src/main/kotlin/Formats/StructuredFormatService.kt | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'core/src/main/kotlin') 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 "${formatText(text)}" } - override fun appendBlockCode(to: StringBuilder, line: String, language: String) { + override fun appendBlockCode(to: StringBuilder, lines: List, language: String) { to.append("
")
-        to.append(line)
+        to.append(lines.joinToString("\n"))
         to.append("
") } 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") } - override fun appendBlockCode(to: StringBuilder, line: String, language: String) { + override fun appendBlockCode(to: StringBuilder, lines: List, language: String) { if (language.isNotEmpty()) { - super.appendBlockCode(to, line, language) + super.appendBlockCode(to, lines, language) } else { to.append("
")
-            to.append(line.trimStart())
+            to.append(lines.joinToString { "\n" }.trimStart())
             to.append("
") } } 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, 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, 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)) } -- cgit