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 ++--- src/Kotlin/ContentBuilder.kt | 2 +- src/Model/Content.kt | 2 +- 6 files changed, 15 insertions(+), 34 deletions(-) (limited to 'src') 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)) } diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 4b8897b2..11c40743 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -157,7 +157,7 @@ fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functio val lines = text.trimTrailing().split("\n").filterNot { it.length() == 0 } val indent = lines.map { it.takeWhile { it.isWhitespace() }.count() }.min() ?: 0 val finalText = lines.map { it.drop(indent) }.join("\n") - return ContentBlockCode().let() { it.append(ContentText(finalText)); it } + return ContentBlockCode("kotlin").let() { it.append(ContentText(finalText)); it } } private fun DocumentationBuilder.resolveInScope(functionName: String, scope: JetScope): DeclarationDescriptor? { diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 66267496..ca5dd49b 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -37,7 +37,7 @@ public class ContentEmphasis() : ContentBlock() public class ContentStrong() : ContentBlock() public class ContentStrikethrough() : ContentBlock() public class ContentCode() : ContentBlock() -public class ContentBlockCode() : ContentBlock() +public class ContentBlockCode(val language: String = "") : ContentBlock() public abstract class ContentNodeLink() : ContentBlock() { abstract val node: DocumentationNode? -- cgit