on fb71a21 help sign in
29 lines 833 B history raw
1module Text.Hakyll.Util
2 ( trim
3 , stripHTML
4 , link
5 ) where
7import Data.Char (isSpace)
9-- | Trim a string (drop spaces and tabs at both sides).
10trim :: String -> String
11trim = reverse . trim' . reverse . trim'
12 where trim' = dropWhile isSpace
14-- | Strip html tags.
15stripHTML :: String -> String
16stripHTML [] = []
17stripHTML str = let (beforeTag, rest) = break (== '<') str
18 (_, afterTag) = break (== '>') rest
19 in beforeTag ++ (stripHTML $ tail' afterTag)
20 -- We need a failsafe tail function.
21 where tail' [] = []
22 tail' xs = tail xs
24-- | Make a HTML link.
25--
26-- > link "foo" "bar.html" == "<a href='bar.html'>foo</a>"
27link :: String -> String -> String
28link text destination = "<a href=\"" ++ destination ++ "\">"
29 ++ text ++ "</a>"