From e8e464ef00d9ee2925204d6c99a7fea8df3798a3 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 17 Jun 2022 21:48:39 +0200 Subject: [PATCH] Add content pretty printer --- src/org/org_types.nim | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/org/org_types.nim b/src/org/org_types.nim index 793d668..c5563ae 100644 --- a/src/org/org_types.nim +++ b/src/org/org_types.nim @@ -66,6 +66,8 @@ proc `$`*(x: orgInlineBlockKind): string = # Links of orgLink: "Link" +const PPRINT_INDENT_SIZE* = 2 + func pprint*(x: OrgInlineBlock, indent = 0): string = let specialFields = case x.kind: of orgLink: @@ -110,7 +112,7 @@ type level*: int todo*: Option[string] headlineContent*: seq[OrgInlineBlock] - content*: string + content*: seq[OrgBlock] of orgParagraph: paragraphContent: seq[OrgInlineBlock] of orgNewline: discard @@ -126,7 +128,14 @@ func pprint*(x: OrgBlock, indent = 0): string = ("todo", $x.todo, x.todo.isSome()), ("headlineContent", $x.headlineContent, x.headlineContent.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: @[ @@ -186,6 +195,14 @@ when isMainModule: linkDescription: "Placeholder".some(), ), ], + content: @[ + OrgBlock( + kind: orgNewline, + ), + OrgBlock( + kind: orgNewline, + ) + ], ), OrgBlock(kind: orgHeading, level: 1), OrgBlock(kind: orgHeading),