Generating markup
This commit is contained in:
@@ -10,6 +10,8 @@ import strformat
|
||||
import ../../org/org_block_heading
|
||||
import ../../org/org_builder
|
||||
import ../../org/org_types
|
||||
import ../../parser/parser_types
|
||||
import ../parser/utils
|
||||
|
||||
proc renderItems(
|
||||
onClick: proc(e: react_types.Event): void,
|
||||
@@ -22,27 +24,62 @@ proc renderItems(
|
||||
&"Add button {count.get(0)}"
|
||||
)
|
||||
|
||||
proc toMarkUp(x: OrgInlineBlock): ReactNode =
|
||||
console.log(x)
|
||||
case x.kind:
|
||||
of orgRawText: p(Attrs{}, x.content)
|
||||
else: p(Attrs{}, "Unmatched")
|
||||
# of orgText: "Text"
|
||||
|
||||
# # Formating
|
||||
# of orgBoldText: "Text (Bold)"
|
||||
# of orgItalicText: "Text (Italic)"
|
||||
# of orgUnderlineText: "Text (Underline)"
|
||||
# of orgVerbatimText: "Text (Verbatim)"
|
||||
# of orgCodeText: "Text (Code)"
|
||||
# of orgStrikeThroughText: "Text (StrikeThrough)"
|
||||
|
||||
# # Links
|
||||
# of orgLink: "Link"
|
||||
|
||||
proc makeItems(x: string): seq[ReactNode] =
|
||||
makeOrg(x)
|
||||
.fold(
|
||||
(err) => @[`div`(Attrs{}, &"Errors: {err}")],
|
||||
(xs: OrgBuilder) => xs.tree.map((x: OrgBlock) => `div`(Attrs{}, x.headlineContent.map(toMarkUp))),
|
||||
)
|
||||
|
||||
proc makeTopLevel(): ReactNode {.exportc.} =
|
||||
let text = myUseState[cstring]("")
|
||||
let text = myUseState[cstring]("""* TODO Level 1
|
||||
Some stuff inbetween
|
||||
|
||||
** DONE Level 2""")
|
||||
|
||||
let val = text.getter
|
||||
let orgItems: seq[string] = makeOrg($val)
|
||||
.foldOrg()
|
||||
|
||||
|
||||
console.log(orgItems)
|
||||
let orgItems = makeItems($val)
|
||||
# .foldBuilder(
|
||||
# err => "",
|
||||
# xs => "Parser Succesfull:\n",
|
||||
# )
|
||||
# .foldBuilder(
|
||||
# # (err) => @[`div`(Attrs{}, "Error!")],
|
||||
# # (xs: seq[OrgBlock]) => @[`div`(Attrs{}, "Error!")],
|
||||
# (err) => "Foo",
|
||||
# (xs) => "Bar",
|
||||
# )
|
||||
|
||||
`div`(
|
||||
Attrs{style: Style{marginTop: 50}},
|
||||
@[
|
||||
textarea(
|
||||
Attrs{
|
||||
onchange: proc(e: react_types.Event): void = discard text.setter(e.target.value)
|
||||
onchange: proc(e: react_types.Event): void = discard text.setter(e.target.value),
|
||||
value: val,
|
||||
},
|
||||
),
|
||||
`div`(
|
||||
Attrs{},
|
||||
$orgItems
|
||||
orgItems
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import std/sugar
|
||||
import results
|
||||
import std/collections/sequtils
|
||||
import ./org_types
|
||||
import results
|
||||
import ../parser/parser_types
|
||||
|
||||
## Inline Blocks
|
||||
|
||||
@@ -46,6 +46,7 @@ type
|
||||
parser: Parser,
|
||||
tree: seq[T]
|
||||
]
|
||||
|
||||
BuilderResult*[T] = Result[Builder[T], (Builder[T], string)]
|
||||
|
||||
# SingleBuilder*[T] = tuple[
|
||||
|
||||
Reference in New Issue
Block a user