@@ -12,6 +12,9 @@ newtype Html
12
12
newtype Structure
13
13
= Structure String
14
14
15
+ newtype Content
16
+ = Content String
17
+
15
18
type Title
16
19
= String
17
20
@@ -26,11 +29,13 @@ html_ title content =
26
29
)
27
30
)
28
31
29
- p_ :: String -> Structure
30
- p_ = Structure . el " p" . escape
32
+ -- * Structure
33
+
34
+ p_ :: Content -> Structure
35
+ p_ = Structure . el " p" . getContentString
31
36
32
- h_ :: Natural -> String -> Structure
33
- h_ n = Structure . el (" h" <> show n) . escape
37
+ h_ :: Natural -> Content -> Structure
38
+ h_ n = Structure . el (" h" <> show n) . getContentString
34
39
35
40
ul_ :: [Structure ] -> Structure
36
41
ul_ =
@@ -50,6 +55,38 @@ instance Semigroup Structure where
50
55
instance Monoid Structure where
51
56
mempty = Structure " "
52
57
58
+ -- * Content
59
+
60
+ txt_ :: String -> Content
61
+ txt_ = Content . escape
62
+
63
+ link_ :: FilePath -> Content -> Content
64
+ link_ path content =
65
+ Content $
66
+ elAttr
67
+ " a"
68
+ (" href=\" " <> escape path <> " \" " )
69
+ (getContentString content)
70
+
71
+ img_ :: FilePath -> Content
72
+ img_ path =
73
+ Content $ " <img src=\" " <> escape path <> " \" >"
74
+
75
+ b_ :: Content -> Content
76
+ b_ content =
77
+ Content $ el " b" (getContentString content)
78
+
79
+ i_ :: Content -> Content
80
+ i_ content =
81
+ Content $ el " i" (getContentString content)
82
+
83
+ instance Semigroup Content where
84
+ (<>) c1 c2 =
85
+ Content (getContentString c1 <> getContentString c2)
86
+
87
+ instance Monoid Content where
88
+ mempty = Content " "
89
+
53
90
-- * Render
54
91
55
92
render :: Html -> String
@@ -63,11 +100,20 @@ el :: String -> String -> String
63
100
el tag content =
64
101
" <" <> tag <> " >" <> content <> " </" <> tag <> " >"
65
102
103
+ elAttr :: String -> String -> String -> String
104
+ elAttr tag attrs content =
105
+ " <" <> tag <> " " <> attrs <> " >" <> content <> " </" <> tag <> " >"
106
+
66
107
getStructureString :: Structure -> String
67
- getStructureString content =
68
- case content of
108
+ getStructureString structure =
109
+ case structure of
69
110
Structure str -> str
70
111
112
+ getContentString :: Content -> String
113
+ getContentString content =
114
+ case content of
115
+ Content str -> str
116
+
71
117
escape :: String -> String
72
118
escape =
73
119
let
0 commit comments