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