Parse content
This commit is contained in:
@@ -31,9 +31,12 @@ let doneKeywords = @["DONE"]
|
|||||||
let parseTodoKeyword = todoKeywords.createTodoKeywordParser()
|
let parseTodoKeyword = todoKeywords.createTodoKeywordParser()
|
||||||
let parseDoneKeyword = doneKeywords.createTodoKeywordParser()
|
let parseDoneKeyword = doneKeywords.createTodoKeywordParser()
|
||||||
|
|
||||||
|
let parseContentText = @[
|
||||||
|
anyUntil(choice(@[endOfStream, str("\n*")])),
|
||||||
|
]
|
||||||
|
|
||||||
let parseHeadingText = @[
|
let parseHeadingText = @[
|
||||||
anyUntil(newline),
|
anyUntil(newline),
|
||||||
ignore(newline),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# func buildStars(token: seq[ParserToken]): seq[ParserToken] =
|
# func buildStars(token: seq[ParserToken]): seq[ParserToken] =
|
||||||
@@ -61,6 +64,11 @@ let buildHeadlineContent = func(tokens: seq[ParserToken], org: OrgBlock): OrgBlo
|
|||||||
org.headlineContent = tokens
|
org.headlineContent = tokens
|
||||||
org
|
org
|
||||||
|
|
||||||
|
let buildHeadlineChildren = func(tokens: seq[ParserToken], org: OrgBlock): OrgBlock {.closure.}=
|
||||||
|
# let headlineString = tokens.tokensToString()
|
||||||
|
|
||||||
|
org.headlineChildrenText = tokens.tokensToString()
|
||||||
|
org
|
||||||
|
|
||||||
proc tryBuildHeading(builder: OrgBuilderResult): OrgBuilderResult =
|
proc tryBuildHeading(builder: OrgBuilderResult): OrgBuilderResult =
|
||||||
builder
|
builder
|
||||||
@@ -73,13 +81,13 @@ proc tryBuildHeading(builder: OrgBuilderResult): OrgBuilderResult =
|
|||||||
(@[optional(parseDoneKeyword)], buildTodo, true),
|
(@[optional(parseDoneKeyword)], buildTodo, true),
|
||||||
|
|
||||||
(parseHeadingText, buildHeadlineContent, false),
|
(parseHeadingText, buildHeadlineContent, false),
|
||||||
|
|
||||||
|
(parseContentText, buildHeadlineChildren, true)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let test = initOrgBuilder("""* TODO Level 1
|
let test = initOrgBuilder("""* TODO Level 1""")
|
||||||
** DONE Level 2
|
|
||||||
""")
|
|
||||||
.tryBuildHeading()
|
.tryBuildHeading()
|
||||||
.fold(
|
.fold(
|
||||||
x => "Nothing",
|
x => "Nothing",
|
||||||
|
|||||||
@@ -92,13 +92,15 @@ type
|
|||||||
level*: int
|
level*: int
|
||||||
todo*: Option[string]
|
todo*: Option[string]
|
||||||
headlineContent*: seq[OrgInlineBlock]
|
headlineContent*: seq[OrgInlineBlock]
|
||||||
|
headlineChildrenText*: string
|
||||||
|
|
||||||
func stringifySpecialFields(x: OrgBlock): string =
|
func stringifySpecialFields(x: OrgBlock): string =
|
||||||
let specialFields = case x.kind:
|
let specialFields = case x.kind:
|
||||||
of orgHeading:
|
of orgHeading:
|
||||||
&"""level: {x.level}
|
&"""level: {x.level}
|
||||||
todo: {x.todo}
|
todo: {x.todo}
|
||||||
headlineContent: {x.headlineContent}"""
|
headlineContent: {x.headlineContent}
|
||||||
|
headlineChildrenText: {x.headlineChildrenText}"""
|
||||||
else: ""
|
else: ""
|
||||||
|
|
||||||
specialFields
|
specialFields
|
||||||
|
|||||||
Reference in New Issue
Block a user