aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2016-03-31 21:04:27 +0200
committerDmitry Jemerov <yole@jetbrains.com>2016-03-31 21:04:27 +0200
commit792ae5c4099c7a37815888cd1313404375453eea (patch)
treee548045fd0095415f3d530149ca0385bd9831aa0 /core
parent07a6e686db79bf7279381bccad79a0d4842f95c2 (diff)
downloaddokka-792ae5c4099c7a37815888cd1313404375453eea.tar.gz
dokka-792ae5c4099c7a37815888cd1313404375453eea.tar.bz2
dokka-792ae5c4099c7a37815888cd1313404375453eea.zip
Don't lose line breaks in code blocks. Resolves #54
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt4
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt4
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt4
-rw-r--r--core/testdata/format/codeBlock.kt13
-rw-r--r--core/testdata/format/codeBlock.md31
-rw-r--r--core/testdata/format/javadocHtml.md2
8 files changed, 59 insertions, 11 deletions
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 "<span class=\"identifier\"$id>${formatText(text)}</span>"
}
- override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ override fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String) {
to.append("<pre><code>")
- to.append(line)
+ to.append(lines.joinToString("\n"))
to.append("</code></pre>")
}
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</td>")
}
- override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
+ override fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String) {
if (language.isNotEmpty()) {
- super.appendBlockCode(to, line, language)
+ super.appendBlockCode(to, lines, language)
} else {
to.append("<pre markdown=\"1\">")
- to.append(line.trimStart())
+ to.append(lines.joinToString { "\n" }.trimStart())
to.append("</pre>")
}
}
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<String>, 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<String>, 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))
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 15be6c77..508790b1 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -246,6 +246,10 @@ class MarkdownFormatTest {
verifyMarkdownNode("jdkLinks", withKotlinRuntime = true)
}
+ @Test fun codeBlock() {
+ verifyMarkdownNode("codeBlock")
+ }
+
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
markdownService.appendNodes(tempLocation, output, model.members)
diff --git a/core/testdata/format/codeBlock.kt b/core/testdata/format/codeBlock.kt
new file mode 100644
index 00000000..e3fa27d2
--- /dev/null
+++ b/core/testdata/format/codeBlock.kt
@@ -0,0 +1,13 @@
+import kotlin.reflect.KClass
+
+/**
+ * This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.
+ *
+ * Example:
+ *
+ * ```
+ * Throws(IOException::class)
+ * fun readFile(name: String): String {...}
+ * ```
+ */
+class Throws
diff --git a/core/testdata/format/codeBlock.md b/core/testdata/format/codeBlock.md
new file mode 100644
index 00000000..08710390
--- /dev/null
+++ b/core/testdata/format/codeBlock.md
@@ -0,0 +1,31 @@
+[test](test/index) / [Throws](test/-throws/index)
+
+
+# Throws
+
+`class Throws`
+
+This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.
+
+
+Example:
+
+
+```
+Throws(IOException::class)
+fun readFile(name: String): String {...}
+```
+
+
+
+
+
+
+### Constructors
+
+
+| [&lt;init&gt;](test/-throws/-init-) | `Throws()`
+This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.
+
+ |
+
diff --git a/core/testdata/format/javadocHtml.md b/core/testdata/format/javadocHtml.md
index db71cc3b..3e92441b 100644
--- a/core/testdata/format/javadocHtml.md
+++ b/core/testdata/format/javadocHtml.md
@@ -9,7 +9,7 @@
Paragraph
~~Strikethrough~~ ~~Deleted~~ `Code`
-```
+```
Block code
```