From 7c6da4babd01da31c57c5c6c827eb2957c989b1c Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 3 Oct 2014 19:09:31 +0400 Subject: Language Service now formats to ContentNode instead of String. --- src/Model/Content.kt | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/Model/Content.kt') diff --git a/src/Model/Content.kt b/src/Model/Content.kt index eb092cb2..1b00bd34 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -9,18 +9,37 @@ public abstract class ContentNode { val empty = ContentEmpty } + fun append(node : ContentNode) : ContentNode { + children.add(node) + return this + } + fun isEmpty() = children.isEmpty() } -public object ContentEmpty : ContentNode( ) +public object ContentEmpty : ContentNode() -public class ContentText(val text : String) : ContentNode( ) -public class ContentBlock() : ContentNode( ) +public class ContentText(val text: String) : ContentNode() +public class ContentKeyword(val text: String) : ContentNode() +public class ContentIdentifier(val text: String) : ContentNode() +public class ContentSymbol(val text: String) : ContentNode() +public class ContentBlock() : ContentNode() public class ContentEmphasis() : ContentNode() public class ContentStrong() : ContentNode() public class ContentList() : ContentNode() public class ContentSection(public val label: String) : ContentNode() +fun content(body: ContentNode.() -> Unit): ContentNode { + val block = ContentBlock() + block.body() + return block +} + +fun ContentNode.text(value: String) = append(ContentText(value)) +fun ContentNode.keyword(value: String) = append(ContentKeyword(value)) +fun ContentNode.symbol(value: String) = append(ContentSymbol(value)) +fun ContentNode.identifier(value: String) = append(ContentIdentifier(value)) + public class Content() : ContentNode() { public val sections: Map by Delegates.lazy { val map = hashMapOf() -- cgit