-
Notifications
You must be signed in to change notification settings - Fork 6
/
Html.hs
42 lines (28 loc) · 910 Bytes
/
Html.hs
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
35
36
37
38
39
40
41
42
module Html where
type HTML = String
tag :: String -> HTML -> HTML
tag t content = "<" ++ t ++ ">" ++ content ++ "</" ++ t ++ ">"
div :: String -> HTML -> HTML
div klass content =
"<div class=\"" ++ klass ++ "\">" ++ content ++ "</div>"
hn :: Int -> HTML -> HTML
hn n = tag ("h" ++ show n)
h5 :: HTML -> HTML
h5 = hn 5
h3 :: HTML -> HTML
h3 = hn 3
h2 :: HTML -> HTML
h2 = hn 2
p :: HTML -> HTML
p = tag "p"
ulist :: [HTML] -> HTML
ulist items = "<ul>" ++ concatMap (\item -> "<li>" ++ item ++ "</li>") items ++ "</ul>"
ddt :: (HTML, HTML) -> HTML
ddt (term, desc) = "<dt>" ++ term ++ "</dt><dd>" ++ desc ++ "</dd>"
anchor :: String -> HTML -> HTML
anchor url content = "<a href=\"" ++ url ++ "\">" ++ content ++ "</a>"
img :: String -> HTML
img url = "<img src=\"" ++ url ++ "\">"
emailToHTML :: String -> HTML
emailToHTML emailAddr =
anchor ("mailto:" ++ emailAddr) ("Email: " ++ emailAddr)