aboutsummaryrefslogtreecommitdiff
path: root/src/Model/PackageDocs.kt
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-03-23 18:52:05 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-03-23 18:52:05 +0100
commit76e4d3cbc7cbbe1d35fb2e0c1ba59d3c86e0daf2 (patch)
treeefc5fc2e5dce290fbca9d55c12f0056b96735c3b /src/Model/PackageDocs.kt
parent73bd875b621fedce84015c50b6954509f4978a6d (diff)
downloaddokka-76e4d3cbc7cbbe1d35fb2e0c1ba59d3c86e0daf2.tar.gz
dokka-76e4d3cbc7cbbe1d35fb2e0c1ba59d3c86e0daf2.tar.bz2
dokka-76e4d3cbc7cbbe1d35fb2e0c1ba59d3c86e0daf2.zip
parse included Markdown files to retrieve documentation for modules and packages
Diffstat (limited to 'src/Model/PackageDocs.kt')
-rw-r--r--src/Model/PackageDocs.kt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Model/PackageDocs.kt b/src/Model/PackageDocs.kt
new file mode 100644
index 00000000..3b0be547
--- /dev/null
+++ b/src/Model/PackageDocs.kt
@@ -0,0 +1,56 @@
+package org.jetbrains.dokka
+
+import org.intellij.markdown.MarkdownElementTypes
+import org.intellij.markdown.MarkdownTokenTypes
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+import java.io.File
+
+public class PackageDocs(val documentationBuilder: DocumentationBuilder,
+ val linkResolveContext: DeclarationDescriptor?,
+ val logger: DokkaLogger) {
+ public val moduleContent: MutableContent = MutableContent()
+ private val _packageContent: MutableMap<String, MutableContent> = hashMapOf()
+ public val packageContent: Map<String, Content>
+ get() = _packageContent
+
+ fun parse(file: String) {
+ val file = File(file)
+ if (file.exists()) {
+ val text = file.readText()
+ val tree = parseMarkdown(text)
+ var targetContent: MutableContent = moduleContent
+ tree.children.forEach {
+ if (it.type == MarkdownElementTypes.ATX_1) {
+ val headingText = it.child(MarkdownTokenTypes.TEXT)?.text
+ if (headingText != null) {
+ targetContent = findTargetContent(headingText)
+ }
+ } else {
+ buildContentTo(it, targetContent, { resolveContentLink(it) })
+ }
+ }
+ } else {
+ logger.warn("Include file $file was not found.")
+ }
+ }
+
+ private fun findTargetContent(heading: String): MutableContent {
+ if (heading.startsWith("Module") || heading.startsWith("module")) {
+ return moduleContent
+ }
+ if (heading.startsWith("Package") || heading.startsWith("package")) {
+ return findOrCreatePackageContent(heading.substring("package".length()).trim())
+ }
+ return findOrCreatePackageContent(heading)
+ }
+
+ private fun findOrCreatePackageContent(packageName: String) =
+ _packageContent.getOrPut(packageName) { -> MutableContent() }
+
+ private fun resolveContentLink(href: String): ContentBlock {
+ if (linkResolveContext != null) {
+ return documentationBuilder.resolveContentLink(linkResolveContext, href)
+ }
+ return ContentExternalLink("#")
+ }
+} \ No newline at end of file