-- | Miscellaneous text manipulation functions. module Text.Hakyll.Util ( trim , stripHtml , link ) where import Data.Char (isSpace) import Text.Blaze.Html5 ((!), string, stringValue, a) import Text.Blaze.Html5.Attributes (href) import Text.Blaze.Renderer.String (renderHtml) -- | Trim a string (drop spaces, tabs and newlines at both sides). trim :: String -> String trim = reverse . trim' . reverse . trim' where trim' = dropWhile isSpace -- | Strip html tags from the given string. stripHtml :: String -> String stripHtml [] = [] stripHtml str = let (beforeTag, rest) = break (== '<') str (_, afterTag) = break (== '>') rest in beforeTag ++ stripHtml (drop 1 afterTag) -- | Make a HTML link. -- -- > link "foo" "bar.html" == "foo" link :: String -- ^ Link text. -> String -- ^ Link destination. -> String link text destination = renderHtml $ a ! href (stringValue destination) $ string text