aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/HtmlFormatService.kt8
-rw-r--r--src/Formats/KotlinWebsiteFormatService.kt19
-rw-r--r--src/Formats/MarkdownFormatService.kt13
-rw-r--r--src/Formats/StructuredFormatService.kt5
4 files changed, 13 insertions, 32 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt
index 46e4be4a..a3cea96a 100644
--- a/src/Formats/HtmlFormatService.kt
+++ b/src/Formats/HtmlFormatService.kt
@@ -22,18 +22,12 @@ public open class HtmlFormatService(locationService: LocationService,
return "<span class=\"identifier\">${formatText(text)}</span>"
}
- override fun appendBlockCode(to: StringBuilder, line: String) {
+ override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
to.append("<pre><code>")
to.append(line)
to.append("</code></pre>")
}
- override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
- to.append("<pre><code>")
- to.append(lines.join("\n"))
- to.append("</code></pre>")
- }
-
override fun appendHeader(to: StringBuilder, text: String, level: Int) {
to.appendln("<h$level>${text}</h$level>")
}
diff --git a/src/Formats/KotlinWebsiteFormatService.kt b/src/Formats/KotlinWebsiteFormatService.kt
index dd33f5c4..a009132b 100644
--- a/src/Formats/KotlinWebsiteFormatService.kt
+++ b/src/Formats/KotlinWebsiteFormatService.kt
@@ -63,17 +63,14 @@ public class KotlinWebsiteFormatService(locationService: LocationService,
to.appendln("\n</td>")
}
- override public fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
- to.append("<pre markdown=\"1\">")
- for (line in lines)
- to.appendln(line)
- to.append(to, "</pre>")
- }
-
- override public fun appendBlockCode(to: StringBuilder, line: String) {
- to.append("<pre markdown=\"1\">")
- to.append(line.trimLeading())
- to.append("</pre>")
+ override public fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ if (language.isNotEmpty()) {
+ super.appendBlockCode(to, line, language)
+ } else {
+ to.append("<pre markdown=\"1\">")
+ to.append(line.trimLeading())
+ to.append("</pre>")
+ }
}
override fun formatSymbol(text: String): String {
diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt
index 2ea169dd..c3f4f469 100644
--- a/src/Formats/MarkdownFormatService.kt
+++ b/src/Formats/MarkdownFormatService.kt
@@ -75,18 +75,9 @@ public open class MarkdownFormatService(locationService: LocationService,
appendLine(to)
}
- override public fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
+ override public fun appendBlockCode(to: StringBuilder, line: String, language: String) {
appendLine(to)
- appendLine(to, "```")
- for (line in lines)
- to.appendln(line)
- appendLine(to, "```")
- appendLine(to)
- }
-
- override public fun appendBlockCode(to: StringBuilder, line: String) {
- appendLine(to)
- to.appendln("```")
+ to.appendln("``` ${language}")
to.appendln(line)
to.appendln("```")
appendLine(to)
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 7535449d..8d8341dd 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -10,8 +10,7 @@ public abstract class StructuredFormatService(locationService: LocationService,
override val extension: String) : FormatService {
val locationService: LocationService = locationService.withExtension(extension)
- abstract public fun appendBlockCode(to: StringBuilder, line: String)
- abstract public fun appendBlockCode(to: StringBuilder, lines: Iterable<String>)
+ abstract public fun appendBlockCode(to: StringBuilder, line: String, language: String)
abstract public fun appendHeader(to: StringBuilder, text: String, level: Int = 1)
abstract public fun appendParagraph(to: StringBuilder, text: String)
abstract public fun appendLine(to: StringBuilder, text: String)
@@ -72,7 +71,7 @@ public abstract class StructuredFormatService(locationService: LocationService,
appendParagraph(this, formatText(location, content.children))
}
is ContentBlockCode -> {
- appendBlockCode(this, formatText(location, content.children))
+ appendBlockCode(this, formatText(location, content.children), content.language)
}
is ContentBlock -> append(formatText(location, content.children))
}