diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-10 18:32:12 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-10 18:32:12 +0100 |
commit | 0d0fc1f2bf8f09106e53626bc024298dc91361b8 (patch) | |
tree | 7364f5a98dacdad3524389c0d818b32ab2641009 /src/Kotlin/ContentBuilder.kt | |
parent | 92075236fb1356fe6023edff1e43fe3125b76c18 (diff) | |
download | dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.tar.gz dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.tar.bz2 dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.zip |
distinguish ContentBlock (a ContentNode that has children) from leaf nodes
Diffstat (limited to 'src/Kotlin/ContentBuilder.kt')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 60b0e9e9..3d44c11b 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -16,9 +16,9 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownNode): Content { return result } -public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: ContentNode) { +public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: ContentBlock) { // println(tree.toTestString()) - val nodeStack = ArrayDeque<ContentNode>() + val nodeStack = ArrayDeque<ContentBlock>() nodeStack.push(target) tree.visit {(node, processChildren) -> @@ -85,16 +85,13 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte MarkdownTokenTypes.WHITE_SPACE, MarkdownTokenTypes.EOL -> { if (keepWhitespace(nodeStack.peek()) && node.parent?.children?.last() != node) { - nodeStack.push(ContentText(node.text)) - processChildren() - parent.append(nodeStack.pop()) + parent.append(ContentText(node.text)) } } - MarkdownTokenTypes.TEXT -> { - nodeStack.push(ContentText(node.text)) - processChildren() - parent.append(nodeStack.pop()) - } + + MarkdownTokenTypes.TEXT -> + parent.append(ContentText(node.text)) + MarkdownTokenTypes.CODE -> { val block = ContentBlockCode() block.append(ContentText(node.text)) @@ -124,7 +121,7 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection -public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: ContentNode) { +public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: ContentBlock) { val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree) inlineContent.forEach { buildContentTo(it, target) |