Finish pretty printer for blocks
This commit is contained in:
@@ -85,7 +85,9 @@ proc `$`*(x: OrgInlineBlock): string =
|
|||||||
"""
|
"""
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
## Block
|
## OrgBlock
|
||||||
|
## --------
|
||||||
|
|
||||||
type
|
type
|
||||||
orgBlockKind* = enum
|
orgBlockKind* = enum
|
||||||
orgHeading
|
orgHeading
|
||||||
@@ -100,7 +102,7 @@ type
|
|||||||
headlineContent*: seq[OrgInlineBlock]
|
headlineContent*: seq[OrgInlineBlock]
|
||||||
headlineChildrenText*: string
|
headlineChildrenText*: string
|
||||||
|
|
||||||
proc `$`*(x: OrgBlock, indent = 0): string =
|
func pprint*(x: OrgBlock, indent = 0): string =
|
||||||
let fieldIndent = indent + INDENT_SIZE
|
let fieldIndent = indent + INDENT_SIZE
|
||||||
let fields = @[
|
let fields = @[
|
||||||
("kind", $x.kind, true),
|
("kind", $x.kind, true),
|
||||||
@@ -119,14 +121,51 @@ proc `$`*(x: OrgBlock, indent = 0): string =
|
|||||||
]
|
]
|
||||||
.join("\n")
|
.join("\n")
|
||||||
|
|
||||||
|
func `$`*(x: OrgBlock): string = pprint(x)
|
||||||
|
|
||||||
|
func pprint*(xs: seq[OrgBlock], indent = 0): string =
|
||||||
|
let fieldIndent = indent + INDENT_SIZE
|
||||||
|
@[
|
||||||
|
"@[",
|
||||||
|
xs
|
||||||
|
.mapIt(it.pprint())
|
||||||
|
.join(",\n")
|
||||||
|
.indent(fieldIndent),
|
||||||
|
"]",
|
||||||
|
]
|
||||||
|
.join("\n")
|
||||||
|
|
||||||
|
func `$`*(xs: seq[OrgBlock]): string = pprint(xs)
|
||||||
|
|
||||||
|
## OrgDocuemnt
|
||||||
|
## -----------
|
||||||
|
|
||||||
type
|
type
|
||||||
OrgDocument* = ref object
|
OrgDocument* = ref object
|
||||||
children*: seq[OrgBlock]
|
children*: seq[OrgBlock]
|
||||||
|
|
||||||
proc `$`*(x: OrgDocument): string =
|
func pprint*(x: OrgDocument, indent = 0): string =
|
||||||
&"""OrgDocument(
|
let fieldIndent = indent + INDENT_SIZE
|
||||||
children: {x.children}
|
|
||||||
)"""
|
let fields = @[
|
||||||
|
("children", $x.children, true),
|
||||||
|
]
|
||||||
|
.stringifyFields()
|
||||||
|
|
||||||
|
@[
|
||||||
|
"OrgDocument(",
|
||||||
|
fields.indent(fieldIndent),
|
||||||
|
")",
|
||||||
|
]
|
||||||
|
.join("\n")
|
||||||
|
|
||||||
|
func `$`*(xs: OrgDocument): string = pprint(xs)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
echo OrgBlock(kind: orgHeading)
|
echo OrgDocument(
|
||||||
|
children: @[
|
||||||
|
OrgBlock(kind: orgHeading),
|
||||||
|
OrgBlock(kind: orgHeading),
|
||||||
|
OrgBlock(kind: orgHeading),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user