hejsan hoppsan
This commit is contained in:
parent
27a169b30c
commit
f971423f04
9 changed files with 264 additions and 98 deletions
53
src/FibLib/constructorHelpers.fs
Normal file
53
src/FibLib/constructorHelpers.fs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
namespace Fibble.FibLib
|
||||
|
||||
open FSharp.Compiler.Text
|
||||
open Fibble.FibLib.Ast
|
||||
|
||||
module Helpers =
|
||||
let emptyAttr ={id=""; classes=[]; kvp=[]}
|
||||
let ah cls kvp =
|
||||
{id=""; classes = [cls]; kvp = Map.toList kvp }
|
||||
let onlyChildren constructor : TagRenderer =
|
||||
fun _ _ _ children -> constructor(children)
|
||||
|
||||
open Helpers
|
||||
|
||||
module ConstructionHelpers =
|
||||
let linebreak _ _ _ _ = LineBreak
|
||||
let softbreak _ _ _ _ = SoftBreak
|
||||
|
||||
let value : TagRenderer =
|
||||
fun meta args _ _ ->
|
||||
match Map.tryFind args.Head meta with
|
||||
| Some(v) -> Text v
|
||||
| None -> Text $"value {args.Head} not found in metadata"
|
||||
|
||||
|
||||
let emph = onlyChildren Emph
|
||||
let underline = onlyChildren Underline
|
||||
let strong = onlyChildren Strong
|
||||
let strikeout = onlyChildren Strikeout
|
||||
let superscript = onlyChildren Superscript
|
||||
let subscript = onlyChildren Subscript
|
||||
|
||||
let image : TagRenderer =
|
||||
fun _ args kwargs children ->
|
||||
let attributes = ah "inlineImage" kwargs
|
||||
Image(attributes,children, args[0])
|
||||
let code : TagRenderer =
|
||||
fun _ _ kwargs children ->
|
||||
let attributes = ah "inlineCode" kwargs
|
||||
match children with
|
||||
| [Text(c)] -> InlineNode.Code(attributes, c)
|
||||
| _ -> failwith "Code tag was not Text,"
|
||||
|
||||
let link : TagRenderer =
|
||||
fun _ args kwargs children ->
|
||||
let attributes = ah "link" kwargs
|
||||
Link(attributes,Target(args[0], children))
|
||||
|
||||
|
||||
|
||||
// blocks
|
||||
let paragraph _ _ _ children = Paragraph(children)
|
||||
let plain _ _ _ children = Plain(children)
|
||||
Loading…
Add table
Add a link
Reference in a new issue