aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-09-10 13:43:53 +0200
committerDmitry Jemerov <yole@jetbrains.com>2015-09-10 13:43:53 +0200
commit8050cf6b6f7205a44ad0adebeaa19e202607f91d (patch)
treeb5ab9e9ab2df2654fb93f3b49b8208a8c712d257
parentaace0f39335c7428ffcfd44cbe1371ecc32ddd08 (diff)
downloaddokka-8050cf6b6f7205a44ad0adebeaa19e202607f91d.tar.gz
dokka-8050cf6b6f7205a44ad0adebeaa19e202607f91d.tar.bz2
dokka-8050cf6b6f7205a44ad0adebeaa19e202607f91d.zip
fix package docs parsing, add test
-rw-r--r--src/Model/PackageDocs.kt8
-rw-r--r--test/data/packagedocs/stdlib.md11
-rw-r--r--test/src/format/PackageDocsTest.kt18
3 files changed, 33 insertions, 4 deletions
diff --git a/src/Model/PackageDocs.kt b/src/Model/PackageDocs.kt
index b5ef2126..68b4dcc1 100644
--- a/src/Model/PackageDocs.kt
+++ b/src/Model/PackageDocs.kt
@@ -5,7 +5,7 @@ import org.intellij.markdown.MarkdownTokenTypes
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import java.io.File
-public class PackageDocs(val documentationBuilder: DocumentationBuilder,
+public class PackageDocs(val documentationBuilder: DocumentationBuilder?,
val linkResolveContext: DeclarationDescriptor?,
val logger: DokkaLogger) {
public val moduleContent: MutableContent = MutableContent()
@@ -21,9 +21,9 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder,
var targetContent: MutableContent = moduleContent
tree.children.forEach {
if (it.type == MarkdownElementTypes.ATX_1) {
- val headingText = it.child(MarkdownTokenTypes.TEXT)?.text
+ val headingText = it.child(MarkdownTokenTypes.ATX_CONTENT)?.text
if (headingText != null) {
- targetContent = findTargetContent(headingText)
+ targetContent = findTargetContent(headingText.trimStart())
}
} else {
buildContentTo(it, targetContent, { resolveContentLink(it) })
@@ -48,7 +48,7 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder,
_packageContent.getOrPut(packageName) { -> MutableContent() }
private fun resolveContentLink(href: String): ContentBlock {
- if (linkResolveContext != null) {
+ if (linkResolveContext != null && documentationBuilder != null) {
return documentationBuilder.resolveContentLink(linkResolveContext, href)
}
return ContentExternalLink("#")
diff --git a/test/data/packagedocs/stdlib.md b/test/data/packagedocs/stdlib.md
new file mode 100644
index 00000000..5d7432b5
--- /dev/null
+++ b/test/data/packagedocs/stdlib.md
@@ -0,0 +1,11 @@
+# Module stdlib
+
+## Kotlin Standard Library
+
+The Kotlin standard library is a set of functions and types implementing idiomatic patterns when working with collections,
+text and files.
+
+# Package kotlin
+
+Core functions and types
+
diff --git a/test/src/format/PackageDocsTest.kt b/test/src/format/PackageDocsTest.kt
new file mode 100644
index 00000000..6815de6f
--- /dev/null
+++ b/test/src/format/PackageDocsTest.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka.tests.format
+
+import org.jetbrains.dokka.ContentBlock
+import org.jetbrains.dokka.ContentText
+import org.jetbrains.dokka.DokkaConsoleLogger
+import org.jetbrains.dokka.PackageDocs
+import org.junit.Test
+import kotlin.test.assertEquals
+
+public class PackageDocsTest {
+ @Test fun verifyParse() {
+ val docs = PackageDocs(null, null, DokkaConsoleLogger)
+ docs.parse("test/data/packagedocs/stdlib.md")
+ val packageContent = docs.packageContent["kotlin"]!!
+ val block = (packageContent.children.single() as ContentBlock).children.first() as ContentText
+ assertEquals("Core functions and types", block.text)
+ }
+}