aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/Formats/GFMFormatService.kt18
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt2
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt2
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt2
-rw-r--r--core/src/main/kotlin/Formats/StandardFormats.kt8
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt6
-rw-r--r--core/src/main/resources/dokka/format/gfm.properties2
-rw-r--r--core/src/test/kotlin/format/GFMFormatTest.kt19
-rw-r--r--core/testdata/format/gfm/sample.kt18
-rw-r--r--core/testdata/format/gfm/sample.md33
10 files changed, 102 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Formats/GFMFormatService.kt b/core/src/main/kotlin/Formats/GFMFormatService.kt
new file mode 100644
index 000000000..7b1eab851
--- /dev/null
+++ b/core/src/main/kotlin/Formats/GFMFormatService.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka
+
+import com.google.inject.Inject
+
+open class GFMFormatService(locationService: LocationService,
+ signatureGenerator: LanguageService,
+ linkExtension: String)
+: MarkdownFormatService(locationService, signatureGenerator, linkExtension) {
+
+ @Inject constructor(locationService: LocationService,
+ signatureGenerator: LanguageService) : this(locationService, signatureGenerator, "md")
+
+ override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
+ to.appendln(columns.joinToString(" | ", "| ", " "))
+ to.appendln("|" + "---|".repeat(columns.size))
+ body()
+ }
+}
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index e6635cef2..c74431289 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -49,7 +49,7 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
to.appendln("<a name=\"${anchor.htmlEscape()}\"></a>")
}
- override fun appendTable(to: StringBuilder, body: () -> Unit) {
+ override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
to.appendln("<table>")
body()
to.appendln("</table>")
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index eba82a3a4..1f3a37509 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -77,7 +77,7 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe
}
}
- override fun appendTable(to: StringBuilder, body: () -> Unit) {
+ override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
to.appendln("<table class=\"api-docs-table\">")
body()
to.appendln("</table>")
diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
index 9684b5c16..791772392 100644
--- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt
+++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
@@ -75,7 +75,7 @@ open class MarkdownFormatService(locationService: LocationService,
appendLine(to)
}
- override fun appendTable(to: StringBuilder, body: () -> Unit) {
+ override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
to.appendln()
body()
to.appendln()
diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt
index 94e1b115a..fdc8eb9e2 100644
--- a/core/src/main/kotlin/Formats/StandardFormats.kt
+++ b/core/src/main/kotlin/Formats/StandardFormats.kt
@@ -1,12 +1,14 @@
package org.jetbrains.dokka.Formats
import org.jetbrains.dokka.*
+import kotlin.reflect.KClass
abstract class KotlinFormatDescriptorBase : FormatDescriptor {
override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class
override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class
override val generatorServiceClass = FileGenerator::class
+ override val outlineServiceClass: KClass<out OutlineFormatService>? = null
}
class HtmlFormatDescriptor : KotlinFormatDescriptorBase() {
@@ -29,10 +31,12 @@ class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() {
class JekyllFormatDescriptor : KotlinFormatDescriptorBase() {
override val formatServiceClass = JekyllFormatService::class
- override val outlineServiceClass = null
}
class MarkdownFormatDescriptor : KotlinFormatDescriptorBase() {
override val formatServiceClass = MarkdownFormatService::class
- override val outlineServiceClass = null
+}
+
+class GFMFormatDescriptor : KotlinFormatDescriptorBase() {
+ override val formatServiceClass = GFMFormatService::class
}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index bb27aab58..72b6833de 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -22,7 +22,7 @@ abstract class StructuredFormatService(locationService: LocationService,
abstract fun appendLine(to: StringBuilder, text: String = "")
abstract fun appendAnchor(to: StringBuilder, anchor: String)
- abstract fun appendTable(to: StringBuilder, body: () -> Unit)
+ abstract fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit)
abstract fun appendTableBody(to: StringBuilder, body: () -> Unit)
abstract fun appendTableRow(to: StringBuilder, body: () -> Unit)
abstract fun appendTableCell(to: StringBuilder, body: () -> Unit)
@@ -355,7 +355,7 @@ abstract class StructuredFormatService(locationService: LocationService,
val children = if (sortMembers) members.sortedBy { it.name } else members
val membersMap = children.groupBy { link(node, it) }
- appendTable(to) {
+ appendTable(to, "Name", "Summary") {
appendTableBody(to) {
for ((memberLocation, members) in membersMap) {
appendTableRow(to) {
@@ -404,7 +404,7 @@ abstract class StructuredFormatService(locationService: LocationService,
to.append(formatText(location, node.owner!!.summary))
appendHeader(to, "All Types", 3)
- appendTable(to) {
+ appendTable(to, "Name", "Summary") {
appendTableBody(to) {
for (type in node.members) {
appendTableRow(to) {
diff --git a/core/src/main/resources/dokka/format/gfm.properties b/core/src/main/resources/dokka/format/gfm.properties
new file mode 100644
index 000000000..5e8f7aa8c
--- /dev/null
+++ b/core/src/main/resources/dokka/format/gfm.properties
@@ -0,0 +1,2 @@
+class=org.jetbrains.dokka.Formats.GFMFormatDescriptor
+description=Produces documentation in GitHub-flavored markdown format
diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt
new file mode 100644
index 000000000..7f7ee2868
--- /dev/null
+++ b/core/src/test/kotlin/format/GFMFormatTest.kt
@@ -0,0 +1,19 @@
+package org.jetbrains.dokka.tests
+
+import org.jetbrains.dokka.GFMFormatService
+import org.jetbrains.dokka.KotlinLanguageService
+import org.junit.Test
+
+class GFMFormatTest {
+ private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService())
+
+ @Test fun sample() {
+ verifyGFMNodeByName("sample", "Foo")
+ }
+
+ private fun verifyGFMNodeByName(fileName: String, name: String) {
+ verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output ->
+ gfmService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == name })
+ }
+ }
+}
diff --git a/core/testdata/format/gfm/sample.kt b/core/testdata/format/gfm/sample.kt
new file mode 100644
index 000000000..3300d2c8c
--- /dev/null
+++ b/core/testdata/format/gfm/sample.kt
@@ -0,0 +1,18 @@
+/**
+ * The class Foo.
+ */
+class Foo {
+ /**
+ * The method bar.
+ */
+ fun bar() {
+
+ }
+
+ /**
+ * The method baz.
+ */
+ fun baz() {
+
+ }
+} \ No newline at end of file
diff --git a/core/testdata/format/gfm/sample.md b/core/testdata/format/gfm/sample.md
new file mode 100644
index 000000000..1555341e3
--- /dev/null
+++ b/core/testdata/format/gfm/sample.md
@@ -0,0 +1,33 @@
+[test](test/index) / [Foo](test/-foo/index)
+
+
+# Foo
+
+`class Foo`
+
+The class Foo.
+
+
+
+
+### Constructors
+
+| Name | Summary
+|---|---|
+| [&lt;init&gt;](test/-foo/-init-) | `Foo()`
+The class Foo.
+
+ |
+
+### Functions
+
+| Name | Summary
+|---|---|
+| [bar](test/-foo/bar) | `fun bar(): Unit`
+The method bar.
+
+ |
+| [baz](test/-foo/baz) | `fun baz(): Unit`
+The method baz.
+
+ |