Add content pretty printer
This commit is contained in:
@@ -66,6 +66,8 @@ proc `$`*(x: orgInlineBlockKind): string =
|
|||||||
# Links
|
# Links
|
||||||
of orgLink: "Link"
|
of orgLink: "Link"
|
||||||
|
|
||||||
|
const PPRINT_INDENT_SIZE* = 2
|
||||||
|
|
||||||
func pprint*(x: OrgInlineBlock, indent = 0): string =
|
func pprint*(x: OrgInlineBlock, indent = 0): string =
|
||||||
let specialFields = case x.kind:
|
let specialFields = case x.kind:
|
||||||
of orgLink:
|
of orgLink:
|
||||||
@@ -110,7 +112,7 @@ type
|
|||||||
level*: int
|
level*: int
|
||||||
todo*: Option[string]
|
todo*: Option[string]
|
||||||
headlineContent*: seq[OrgInlineBlock]
|
headlineContent*: seq[OrgInlineBlock]
|
||||||
content*: string
|
content*: seq[OrgBlock]
|
||||||
of orgParagraph:
|
of orgParagraph:
|
||||||
paragraphContent: seq[OrgInlineBlock]
|
paragraphContent: seq[OrgInlineBlock]
|
||||||
of orgNewline: discard
|
of orgNewline: discard
|
||||||
@@ -126,7 +128,14 @@ func pprint*(x: OrgBlock, indent = 0): string =
|
|||||||
("todo", $x.todo, x.todo.isSome()),
|
("todo", $x.todo, x.todo.isSome()),
|
||||||
("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
|
("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
|
||||||
("children", $x.children, x.children.len != 0),
|
("children", $x.children, x.children.len != 0),
|
||||||
("content", $x.content, x.content != ""),
|
(
|
||||||
|
"content",
|
||||||
|
("@[\n" &
|
||||||
|
x.content.map((x) => pprint(x)).join(",\n").indent(PPRINT_INDENT_SIZE) &
|
||||||
|
",\n],"
|
||||||
|
).indent(indent),
|
||||||
|
x.content.len != 0
|
||||||
|
),
|
||||||
]
|
]
|
||||||
of orgParagraph:
|
of orgParagraph:
|
||||||
@[
|
@[
|
||||||
@@ -186,6 +195,14 @@ when isMainModule:
|
|||||||
linkDescription: "Placeholder".some(),
|
linkDescription: "Placeholder".some(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
content: @[
|
||||||
|
OrgBlock(
|
||||||
|
kind: orgNewline,
|
||||||
|
),
|
||||||
|
OrgBlock(
|
||||||
|
kind: orgNewline,
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
OrgBlock(kind: orgHeading, level: 1),
|
OrgBlock(kind: orgHeading, level: 1),
|
||||||
OrgBlock(kind: orgHeading),
|
OrgBlock(kind: orgHeading),
|
||||||
|
|||||||
Reference in New Issue
Block a user