-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListML.fs
34 lines (26 loc) · 917 Bytes
/
ListML.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace ListML
module Core =
let attr (key:string) (value:string) = key, value
let renderAttribute kv =
let key, value = kv
sprintf "%s=\"%s\"" key value
let checkforClosingTag hasClosingtag trueCond falseCond =
match hasClosingtag with
| true -> trueCond
| false -> falseCond
let node (tag:string) (attributes:(string * string) list) (children: string list) =
let hasClosingtag =
match children with
| [] -> false
| _ -> true
let concat left right = sprintf "%s%s" left right
[
"<"
tag
List.fold (fun left right -> sprintf "%s %s" left (renderAttribute right)) "" attributes
checkforClosingTag hasClosingtag ">" "/>"
List.fold concat "" children
checkforClosingTag hasClosingtag "</" ""
checkforClosingTag hasClosingtag tag ""
checkforClosingTag hasClosingtag ">" ""
] |> List.fold concat ""