diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-26 19:34:49 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-26 19:34:49 +0100 |
commit | 44cef5ccc67c329ea2184aa00e8dc9eac5ca7f77 (patch) | |
tree | 1e389e8e9a91862e94b5901d7ee3d46c9d6bd42c /src | |
parent | 4f59034a9436ff23b021a878dba753b67d62b742 (diff) | |
download | dokka-44cef5ccc67c329ea2184aa00e8dc9eac5ca7f77.tar.gz dokka-44cef5ccc67c329ea2184aa00e8dc9eac5ca7f77.tar.bz2 dokka-44cef5ccc67c329ea2184aa00e8dc9eac5ca7f77.zip |
syntax highlight code examples
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 8 | ||||
-rw-r--r-- | src/Formats/KotlinWebsiteFormatService.kt | 19 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 13 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 5 | ||||
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 2 | ||||
-rw-r--r-- | src/Model/Content.kt | 2 |
6 files changed, 15 insertions, 34 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)) } 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? |