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,11 +111,16 @@ 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:
of orgHeading:
@[
("kind", $x.kind, true), ("kind", $x.kind, true),
("level", $x.level, true), ("level", $x.level, true),
("todo", $x.todo, x.todo.isSome()), ("todo", $x.todo, x.todo.isSome()),
@@ -122,12 +128,20 @@ func pprint*(x: OrgBlock, indent = 0): string =
("children", $x.children, x.children.len != 0), ("children", $x.children, x.children.len != 0),
("content", $x.content, x.content != ""), ("content", $x.content, x.content != ""),
] ]
.stringifyFields() 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)