Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let List/map =
https://prelude.dhall-lang.org/List/map sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680
let Text/concat =
https://prelude.dhall-lang.org/Text/concat sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0
let JSON =
https://prelude.dhall-lang.org/JSON/package.dhall sha256:0c3c40a63108f2e6ad59f23b789c18eb484d0e9aebc9416c5a4f338c6753084b
let Map =
https://prelude.dhall-lang.org/Map/package.dhall sha256:598e9c76103b2686fbbda6cc30078f9e60dd846d9eaf155d0149cf0ae06c21c5
let Location =
https://prelude.dhall-lang.org/Location/Type sha256:613ebb491aeef4ff06368058b4f0e6e3bb8a58d8c145131fc0b947aac045a529
let Content =
< Nodes : List JSON.Type | Markdown : Text | Text : Text | Raw : Text >
let Attr =
< Text : Text | VersionedAsset : { path : Text, location : Location } >
let Node =
{ tag : Optional Text, attrs : Map.Type Text Attr, content : Content }
let emptyNode
: Node
= { tag = None Text
, attrs = Map.empty Text Attr
, content = Content.Nodes ([] : List JSON.Type)
}
let contentToJSON
: Content JSON.Type
= λ(content : Content)
merge
{ Nodes =
λ(ns : List JSON.Type)
JSON.object
(toMap { type = JSON.string "nodes", value = JSON.array ns })
, Markdown =
λ(s : Text)
JSON.object
( toMap
{ type = JSON.string "markdown", value = JSON.string s }
)
, Text =
λ(s : Text)
JSON.object
(toMap { type = JSON.string "text", value = JSON.string s })
, Raw =
λ(s : Text)
JSON.object
(toMap { type = JSON.string "raw", value = JSON.string s })
}
content
let locationToJSON
: Location JSON.Type
= λ(location : Location)
merge
{ Environment =
λ(value : Text)
JSON.object
( toMap
{ type = JSON.string "Environment"
, value = JSON.string value
}
)
, Local =
λ(value : Text)
JSON.object
( toMap
{ type = JSON.string "Local", value = JSON.string value }
)
, Missing = JSON.object (toMap { type = JSON.string "Missing" })
, Remote =
λ(value : Text)
JSON.object
( toMap
{ type = JSON.string "Remote", value = JSON.string value }
)
}
location
let attrToJSON
: Attr JSON.Type
= λ(attr : Attr)
merge
{ Text = λ(value : Text) JSON.string value
, VersionedAsset =
λ(value : { path : Text, location : Location })
JSON.object
( toMap
{ path = JSON.string value.path
, location = locationToJSON value.location
}
)
}
attr
let nodeToJSON
: Node JSON.Type
= λ(node : Node)
JSON.object
( toMap
{ tag =
Optional/fold Text node.tag JSON.Type JSON.string JSON.null
, attrs =
JSON.object
(Map.map Text Attr JSON.Type attrToJSON node.attrs)
, content = contentToJSON node.content
}
)
let node
: Text Node
= λ(tag : Text) emptyNode { tag = Some tag }
let attrs
: Map.Type Text Text { attrs : Map.Type Text Attr }
= λ(xs : Map.Type Text Text)
{ attrs = Map.map Text Text Attr Attr.Text xs }
let attrsFull
: Map.Type Text Attr { attrs : Map.Type Text Attr }
= λ(xs : Map.Type Text Attr) { attrs = xs }
let content
: List Node { content : Content }
= λ(ns : List Node)
{ content = Content.Nodes (List/map Node JSON.Type nodeToJSON ns) }
let nodes
: List Node Node
= λ(ns : List Node) emptyNode content ns
let markdown
: Text Node
= λ(s : Text) emptyNode { content = Content.Markdown s }
let text
: Text Node
= λ(s : Text) emptyNode { content = Content.Text s }
let raw
: Text Node
= λ(s : Text) emptyNode { content = Content.Raw s }
in { Attr = Attr
, Node = Node
, node = node
, locationToJSON = locationToJSON
, nodeToJSON = nodeToJSON
, emptyNode = emptyNode
, text = text
, raw = raw
, markdown = markdown
, attrs = attrs
, attrsFull = attrsFull
, content = content
, nodes = nodes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.