Extract common block pprint functionality

This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent 4c6ca48b8b
commit 4fee450324

View File

@@ -103,7 +103,6 @@ type
headlineChildrenText*: string headlineChildrenText*: string
func pprint*(x: OrgBlock, indent = 0): string = func pprint*(x: OrgBlock, indent = 0): string =
let fieldIndent = indent + INDENT_SIZE
let fields = @[ let fields = @[
("kind", $x.kind, true), ("kind", $x.kind, true),
("level", $x.level, true), ("level", $x.level, true),
@@ -114,12 +113,11 @@ func pprint*(x: OrgBlock, indent = 0): string =
] ]
.stringifyFields() .stringifyFields()
@[ stringifyBlock(
"OrgBlock(", "OrgBlock",
fields.indent(fieldIndent), indent,
")", fields,
] )
.join("\n")
func `$`*(x: OrgBlock): string = pprint(x) func `$`*(x: OrgBlock): string = pprint(x)
@@ -136,6 +134,7 @@ func pprint*(xs: seq[OrgBlock], indent = 0): string =
.join("\n") .join("\n")
func `$`*(xs: seq[OrgBlock]): string = pprint(xs) func `$`*(xs: seq[OrgBlock]): string = pprint(xs)
## OrgDocuemnt ## OrgDocuemnt
## ----------- ## -----------
@@ -145,19 +144,16 @@ type
children*: seq[OrgBlock] children*: seq[OrgBlock]
func pprint*(x: OrgDocument, indent = 0): string = func pprint*(x: OrgDocument, indent = 0): string =
let fieldIndent = indent + INDENT_SIZE
let fields = @[ let fields = @[
("children", $x.children, true), ("children", $x.children, true),
] ]
.stringifyFields() .stringifyFields()
@[ stringifyBlock(
"OrgDocument(", "OrgDocument",
fields.indent(fieldIndent), indent,
")", fields,
] )
.join("\n")
func `$`*(xs: OrgDocument): string = pprint(xs) func `$`*(xs: OrgDocument): string = pprint(xs)