summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Util/Html.hs
blob: 2a4260853ae2e487606565c3b908f94e451d7e58 (plain)
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
43
44
45
46
47
-- | Miscellaneous HTML manipulation functions
--
module Hakyll.Web.Util.Html
    ( stripTags
    , escapeHtml
    ) where

import Text.Blaze (toHtml)
import Text.Blaze.Renderer.String (renderHtml)

-- | Strip all HTML tags from a string
--
-- Example:
--
-- > stripTags "<p>foo</p>"
--
-- Result:
--
-- > "foo"
--
-- This also works for incomplete tags
--
-- Example:
--
-- > stripTags "<p>foo</p"
--
-- Result:
--
-- > "foo"
--
stripTags :: String -> String
stripTags []         = []
stripTags ('<' : xs) = stripTags $ drop 1 $ dropWhile (/= '>') xs
stripTags (x : xs)   = x : stripTags xs

-- | HTML-escape a string
--
-- Example:
--
-- > escapeHtml "Me & Dean"
--
-- Result:
--
-- > "Me &amp; Dean"
--
escapeHtml :: String -> String
escapeHtml = renderHtml . toHtml