summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2011-11-25 23:05:50 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2011-11-25 23:05:50 +0100
commit12b4e8a0b276829747dffd45ddb6fd89d0c61454 (patch)
tree5ad2cb5b1784c57967431f9f4fb23cd21a1b0a30 /src/Hakyll/Web
parent3a4b45ef29cebf9f7110412e005a3dac5d6d6262 (diff)
downloadhakyll-12b4e8a0b276829747dffd45ddb6fd89d0c61454.tar.gz
Add escapeHtml function
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r--src/Hakyll/Web/Blaze.hs4
-rw-r--r--src/Hakyll/Web/Util/Html.hs17
2 files changed, 19 insertions, 2 deletions
diff --git a/src/Hakyll/Web/Blaze.hs b/src/Hakyll/Web/Blaze.hs
index e83b340..f79f036 100644
--- a/src/Hakyll/Web/Blaze.hs
+++ b/src/Hakyll/Web/Blaze.hs
@@ -12,8 +12,8 @@ import Text.Blaze (Html, toHtml, preEscapedString)
import Hakyll.Web.Page
import Hakyll.Web.Page.Metadata
--- | Get a field from a page and convert it to HTML. This version does escape
--- the given HTML
+-- | Get a field from a page and convert it to HTML. This version does not
+-- escape the given HTML
--
getFieldHtml :: String -> Page a -> Html
getFieldHtml key = preEscapedString . getField key
diff --git a/src/Hakyll/Web/Util/Html.hs b/src/Hakyll/Web/Util/Html.hs
index 5330cdd..2a42608 100644
--- a/src/Hakyll/Web/Util/Html.hs
+++ b/src/Hakyll/Web/Util/Html.hs
@@ -2,8 +2,12 @@
--
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:
@@ -28,3 +32,16 @@ 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