diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-03-23 17:04:26 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-03-23 17:04:26 +0100 |
commit | 73bd875b621fedce84015c50b6954509f4978a6d (patch) | |
tree | 74a1a1f98cac6508be8ea3ed2afde862dcf6f973 /src/Kotlin/ContentBuilder.kt | |
parent | 58d9e924fc6c7b94f2b8c3c43bea161716d8dd4f (diff) | |
download | dokka-73bd875b621fedce84015c50b6954509f4978a6d.tar.gz dokka-73bd875b621fedce84015c50b6954509f4978a6d.tar.bz2 dokka-73bd875b621fedce84015c50b6954509f4978a6d.zip |
more compact implementation of Markdown to content tree conversion
Diffstat (limited to 'src/Kotlin/ContentBuilder.kt')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 56 |
1 files changed, 16 insertions, 40 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index ec276a00..742ac58b 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -23,42 +23,23 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver tree.visit {node, processChildren -> val parent = nodeStack.peek()!! + + fun appendNodeWithChildren(content: ContentBlock) { + nodeStack.push(content) + processChildren() + parent.append(nodeStack.pop()) + } + when (node.type) { - MarkdownElementTypes.UNORDERED_LIST -> { - nodeStack.push(ContentUnorderedList()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.ORDERED_LIST -> { - nodeStack.push(ContentOrderedList()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.LIST_ITEM -> { - nodeStack.push(ContentListItem()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.EMPH -> { - nodeStack.push(ContentEmphasis()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.STRONG -> { - nodeStack.push(ContentStrong()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.CODE_SPAN -> { - nodeStack.push(ContentCode()) - processChildren() - parent.append(nodeStack.pop()) - } - MarkdownElementTypes.CODE_BLOCK -> { - nodeStack.push(ContentBlockCode()) - processChildren() - parent.append(nodeStack.pop()) - } + MarkdownElementTypes.UNORDERED_LIST -> appendNodeWithChildren(ContentUnorderedList()) + MarkdownElementTypes.ORDERED_LIST -> appendNodeWithChildren(ContentOrderedList()) + MarkdownElementTypes.LIST_ITEM -> appendNodeWithChildren(ContentListItem()) + MarkdownElementTypes.EMPH -> appendNodeWithChildren(ContentEmphasis()) + MarkdownElementTypes.STRONG -> appendNodeWithChildren(ContentStrong()) + MarkdownElementTypes.CODE_SPAN -> appendNodeWithChildren(ContentCode()) + MarkdownElementTypes.CODE_BLOCK -> appendNodeWithChildren(ContentBlockCode()) + MarkdownElementTypes.PARAGRAPH -> appendNodeWithChildren(ContentParagraph()) + MarkdownElementTypes.INLINE_LINK -> { val label = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT) val destination = node.child(MarkdownElementTypes.LINK_DESTINATION) @@ -96,11 +77,6 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver block.append(ContentText(node.text)) parent.append(block) } - MarkdownElementTypes.PARAGRAPH -> { - nodeStack.push(ContentParagraph()) - processChildren() - parent.append(nodeStack.pop()) - } MarkdownTokenTypes.HTML_ENTITY -> { parent.append(ContentEntity(node.text)) |