From 76e4d3cbc7cbbe1d35fb2e0c1ba59d3c86e0daf2 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 23 Mar 2015 18:52:05 +0100 Subject: parse included Markdown files to retrieve documentation for modules and packages --- src/Formats/StructuredFormatService.kt | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/Formats') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 233dd9e3..0ee3c888 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -84,12 +84,9 @@ public abstract class StructuredFormatService(locationService: LocationService, append(formatLink(linkText, content.href)) } } - is ContentParagraph -> { - appendParagraph(this, formatText(location, content.children)) - } - is ContentBlockCode -> { - appendBlockCode(this, formatText(location, content.children), content.language) - } + is ContentParagraph -> appendParagraph(this, formatText(location, content.children)) + is ContentBlockCode -> appendBlockCode(this, formatText(location, content.children), content.language) + is ContentHeading -> appendHeader(this, formatText(location, content.children), content.level) is ContentBlock -> append(formatText(location, content.children)) } }.toString() @@ -133,6 +130,9 @@ public abstract class StructuredFormatService(locationService: LocationService, } } + private fun DocumentationNode.isModuleOrPackage(): Boolean = + kind == DocumentationNode.Kind.Module || kind == DocumentationNode.Kind.Package + protected open fun appendAsSignature(to: StringBuilder, block: () -> Unit) { block() } @@ -206,10 +206,18 @@ public abstract class StructuredFormatService(locationService: LocationService, } fun appendLocation(location: Location, to: StringBuilder, nodes: Iterable) { - val breakdownByName = nodes.groupBy { node -> node.name } - for ((name, items) in breakdownByName) { - appendHeader(to, formatText(name)) - appendDocumentation(location, to, items) + val singleNode = nodes.singleOrNull() + if (singleNode != null && singleNode.isModuleOrPackage()) { + if (singleNode.kind == DocumentationNode.Kind.Package) { + appendHeader(to, "Package " + formatText(singleNode.name), 2) + } + to.append(formatText(location, singleNode.content)) + } else { + val breakdownByName = nodes.groupBy { node -> node.name } + for ((name, items) in breakdownByName) { + appendHeader(to, formatText(name)) + appendDocumentation(location, to, items) + } } } -- cgit