From 0d0fc1f2bf8f09106e53626bc024298dc91361b8 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 Feb 2015 18:32:12 +0100 Subject: distinguish ContentBlock (a ContentNode that has children) from leaf nodes --- src/Kotlin/ContentBuilder.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/Kotlin/ContentBuilder.kt') 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() + val nodeStack = ArrayDeque() 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) -- cgit