diff options
-rw-r--r-- | src/Model/PackageDocs.kt | 8 | ||||
-rw-r--r-- | test/data/packagedocs/stdlib.md | 11 | ||||
-rw-r--r-- | test/src/format/PackageDocsTest.kt | 18 |
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) + } +} |