From 44cef5ccc67c329ea2184aa00e8dc9eac5ca7f77 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 26 Feb 2015 19:34:49 +0100 Subject: syntax highlight code examples --- src/Formats/HtmlFormatService.kt | 8 +------- src/Formats/KotlinWebsiteFormatService.kt | 19 ++++++++----------- src/Formats/MarkdownFormatService.kt | 13 ++----------- src/Formats/StructuredFormatService.kt | 5 ++--- 4 files changed, 13 insertions(+), 32 deletions(-) (limited to 'src/Formats') 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 "${formatText(text)}" } - override fun appendBlockCode(to: StringBuilder, line: String) { + override fun appendBlockCode(to: StringBuilder, line: String, language: String) { to.append("
")
         to.append(line)
         to.append("
") } - override fun appendBlockCode(to: StringBuilder, lines: Iterable) { - to.append("
")
-        to.append(lines.join("\n"))
-        to.append("
") - } - override fun appendHeader(to: StringBuilder, text: String, level: Int) { to.appendln("${text}") } 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") } - override public fun appendBlockCode(to: StringBuilder, lines: Iterable) { - to.append("
")
-        for (line in lines)
-            to.appendln(line)
-        to.append(to, "
") - } - - override public fun appendBlockCode(to: StringBuilder, line: String) { - to.append("
")
-        to.append(line.trimLeading())
-        to.append("
") + override public fun appendBlockCode(to: StringBuilder, line: String, language: String) { + if (language.isNotEmpty()) { + super.appendBlockCode(to, line, language) + } else { + to.append("
")
+            to.append(line.trimLeading())
+            to.append("
") + } } 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) { + 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) + 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)) } -- cgit