diff options
-rw-r--r-- | hakyll.cabal | 3 | ||||
-rw-r--r-- | src/Hakyll.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Util/Html.hs | 30 | ||||
-rw-r--r-- | tests/Hakyll/Web/Util/Html/Tests.hs | 18 | ||||
-rw-r--r-- | tests/TestSuite.hs | 3 |
5 files changed, 55 insertions, 1 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index 4da2e03..73d0229 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -1,5 +1,5 @@ Name: hakyll -Version: 3.1.2.7 +Version: 3.1.2.8 Synopsis: A static website compiler library Description: @@ -120,6 +120,7 @@ Library Hakyll.Web.Tags Hakyll.Web.Template Hakyll.Web.Template.Read + Hakyll.Web.Util.Html Hakyll.Web.Util.Url Other-Modules: diff --git a/src/Hakyll.hs b/src/Hakyll.hs index a91ea73..268c9ae 100644 --- a/src/Hakyll.hs +++ b/src/Hakyll.hs @@ -29,6 +29,7 @@ module Hakyll , module Hakyll.Web.RelativizeUrls , module Hakyll.Web.Tags , module Hakyll.Web.Template + , module Hakyll.Web.Util.Html , module Hakyll.Web.Util.Url ) where @@ -60,4 +61,5 @@ import Hakyll.Web.Pandoc.FileType import Hakyll.Web.RelativizeUrls import Hakyll.Web.Tags import Hakyll.Web.Template +import Hakyll.Web.Util.Html import Hakyll.Web.Util.Url diff --git a/src/Hakyll/Web/Util/Html.hs b/src/Hakyll/Web/Util/Html.hs new file mode 100644 index 0000000..5330cdd --- /dev/null +++ b/src/Hakyll/Web/Util/Html.hs @@ -0,0 +1,30 @@ +-- | Miscellaneous HTML manipulation functions +-- +module Hakyll.Web.Util.Html + ( stripTags + ) where + +-- | 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 diff --git a/tests/Hakyll/Web/Util/Html/Tests.hs b/tests/Hakyll/Web/Util/Html/Tests.hs new file mode 100644 index 0000000..fc72cdf --- /dev/null +++ b/tests/Hakyll/Web/Util/Html/Tests.hs @@ -0,0 +1,18 @@ +module Hakyll.Web.Util.Html.Tests + ( tests + ) where + +import Test.Framework +import Test.HUnit hiding (Test) + +import Hakyll.Web.Util.Html +import TestSuite.Util + +tests :: [Test] +tests = concat + [ fromAssertions "stripTags" + [ "foo" @=? stripTags "<p>foo</p>" + , "foo bar" @=? stripTags "<p>foo</p> bar" + , "foo" @=? stripTags "<p>foo</p" + ] + ] diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index fe9012d..0f13106 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -12,6 +12,7 @@ import qualified Hakyll.Web.Page.Tests import qualified Hakyll.Web.Page.Metadata.Tests import qualified Hakyll.Web.RelativizeUrls.Tests import qualified Hakyll.Web.Template.Tests +import qualified Hakyll.Web.Util.Html.Tests import qualified Hakyll.Web.Util.Url.Tests main :: IO () @@ -36,6 +37,8 @@ main = defaultMain Hakyll.Web.RelativizeUrls.Tests.tests , testGroup "Hakyll.Web.Template.Tests" Hakyll.Web.Template.Tests.tests + , testGroup "Hakyll.Web.Util.Html.Tests" + Hakyll.Web.Util.Html.Tests.tests , testGroup "Hakyll.Web.Util.Url.Tests" Hakyll.Web.Util.Url.Tests.tests ] |