Extract stringifying functions
This commit is contained in:
@@ -8,6 +8,7 @@ import std/[
|
||||
import fp/[
|
||||
maybe,
|
||||
]
|
||||
import ../utils/printers
|
||||
|
||||
## Inline Block
|
||||
type
|
||||
@@ -102,22 +103,15 @@ type
|
||||
const INDENT_SIZE = 2;
|
||||
|
||||
func stringifySpecialFields(x: OrgBlock, indent = 0): string =
|
||||
(
|
||||
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),
|
||||
("headlineChildrenText", $x.headlineChildrenText, x.headlineChildrenText.len != 0),
|
||||
("children", $x.children, true),
|
||||
]
|
||||
else: @[])
|
||||
|
||||
.filter(x => x[2])
|
||||
.map(x => x[0] & ": " & x[1])
|
||||
.join(",\n")
|
||||
@[
|
||||
("kind", $x.kind, true),
|
||||
("level", $x.level, true),
|
||||
("todo", $x.todo, x.todo.isSome()),
|
||||
("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
|
||||
("headlineChildrenText", $x.headlineChildrenText, x.headlineChildrenText.len != 0),
|
||||
("children", $x.children, true),
|
||||
]
|
||||
.stringifyFields()
|
||||
|
||||
proc `$`*(x: OrgBlock, indent = 0): string =
|
||||
let fieldIndent = indent + INDENT_SIZE
|
||||
|
||||
Reference in New Issue
Block a user