Generating markup
This commit is contained in:
@@ -10,6 +10,8 @@ import strformat
|
|||||||
import ../../org/org_block_heading
|
import ../../org/org_block_heading
|
||||||
import ../../org/org_builder
|
import ../../org/org_builder
|
||||||
import ../../org/org_types
|
import ../../org/org_types
|
||||||
|
import ../../parser/parser_types
|
||||||
|
import ../parser/utils
|
||||||
|
|
||||||
proc renderItems(
|
proc renderItems(
|
||||||
onClick: proc(e: react_types.Event): void,
|
onClick: proc(e: react_types.Event): void,
|
||||||
@@ -22,27 +24,62 @@ proc renderItems(
|
|||||||
&"Add button {count.get(0)}"
|
&"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.} =
|
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 val = text.getter
|
||||||
let orgItems: seq[string] = makeOrg($val)
|
let orgItems = makeItems($val)
|
||||||
.foldOrg()
|
# .foldBuilder(
|
||||||
|
# err => "",
|
||||||
|
# xs => "Parser Succesfull:\n",
|
||||||
console.log(orgItems)
|
# )
|
||||||
|
# .foldBuilder(
|
||||||
|
# # (err) => @[`div`(Attrs{}, "Error!")],
|
||||||
|
# # (xs: seq[OrgBlock]) => @[`div`(Attrs{}, "Error!")],
|
||||||
|
# (err) => "Foo",
|
||||||
|
# (xs) => "Bar",
|
||||||
|
# )
|
||||||
|
|
||||||
`div`(
|
`div`(
|
||||||
Attrs{style: Style{marginTop: 50}},
|
Attrs{style: Style{marginTop: 50}},
|
||||||
@[
|
@[
|
||||||
textarea(
|
textarea(
|
||||||
Attrs{
|
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`(
|
`div`(
|
||||||
Attrs{},
|
Attrs{},
|
||||||
$orgItems
|
orgItems
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import std/sugar
|
|||||||
import results
|
import results
|
||||||
import std/collections/sequtils
|
import std/collections/sequtils
|
||||||
import ./org_types
|
import ./org_types
|
||||||
|
import results
|
||||||
import ../parser/parser_types
|
import ../parser/parser_types
|
||||||
|
|
||||||
## Inline Blocks
|
## Inline Blocks
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ type
|
|||||||
parser: Parser,
|
parser: Parser,
|
||||||
tree: seq[T]
|
tree: seq[T]
|
||||||
]
|
]
|
||||||
|
|
||||||
BuilderResult*[T] = Result[Builder[T], (Builder[T], string)]
|
BuilderResult*[T] = Result[Builder[T], (Builder[T], string)]
|
||||||
|
|
||||||
# SingleBuilder*[T] = tuple[
|
# SingleBuilder*[T] = tuple[
|
||||||
|
|||||||
Reference in New Issue
Block a user