Add paragraph and newline kinds

This commit is contained in:
Florian Schroedl
2022-06-17 17:18:26 +02:00
parent d0b9c0e8b4
commit 832cfe6a06

View File

@@ -100,7 +100,8 @@ func `$`*(xs: seq[OrgInlineBlock]): string = pprint(xs)
type type
orgBlockKind* = enum orgBlockKind* = enum
orgHeading orgHeading
# orgParagraph orgParagraph
orgNewline
OrgBlock* = ref object OrgBlock* = ref object
children*: seq[OrgInlineBlock] children*: seq[OrgInlineBlock]
@@ -110,24 +111,37 @@ type
todo*: Option[string] todo*: Option[string]
headlineContent*: seq[OrgInlineBlock] headlineContent*: seq[OrgInlineBlock]
content*: string content*: string
of orgParagraph:
paragraphContent: seq[OrgInlineBlock]
of orgNewline: discard
## OrgBlock.PrettyPrinters ## OrgBlock.PrettyPrinters
func pprint*(x: OrgBlock, indent = 0): string = func pprint*(x: OrgBlock, indent = 0): string =
let fields = @[ let fields = case x.kind:
("kind", $x.kind, true), of orgHeading:
("level", $x.level, true), @[
("todo", $x.todo, x.todo.isSome()), ("kind", $x.kind, true),
("headlineContent", $x.headlineContent, x.headlineContent.len != 0), ("level", $x.level, true),
("children", $x.children, x.children.len != 0), ("todo", $x.todo, x.todo.isSome()),
("content", $x.content, x.content != ""), ("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
] ("children", $x.children, x.children.len != 0),
.stringifyFields() ("content", $x.content, x.content != ""),
]
of orgParagraph:
@[
("kind", $x.kind, true),
("paragraphContent", $x.paragraphContent, x.paragraphContent.len != 0),
]
else:
@[
("kind", $x.kind, true),
]
stringifyBlock( stringifyBlock(
"OrgBlock", "OrgBlock",
indent, indent,
fields, fields.stringifyFields(),
) )
func `$`*(x: OrgBlock): string = pprint(x) func `$`*(x: OrgBlock): string = pprint(x)