From c0e15825203de704ad6c7c9511dffcbcbd11f959 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Sun, 4 Oct 2020 17:53:24 +0200 Subject: [PATCH] Added stripTags to HaskellSupport --- IHP/HaskellSupport.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/IHP/HaskellSupport.hs b/IHP/HaskellSupport.hs index 0e9fba6e7..24bfe604f 100644 --- a/IHP/HaskellSupport.hs +++ b/IHP/HaskellSupport.hs @@ -27,6 +27,7 @@ module IHP.HaskellSupport ( , todayIsWeekend , debug , includes +, stripTags ) where import ClassyPrelude @@ -41,6 +42,7 @@ import qualified GHC.Records as Record import qualified Data.Attoparsec.ByteString.Char8 as Attoparsec import Data.String.Conversions (cs) import qualified Debug.Trace +import qualified Data.Text as Text --(|>) :: a -> f -> f a infixl 8 |> @@ -230,3 +232,12 @@ isWeekend day = debug :: Show value => value -> value debug value = Debug.Trace.traceShowId value {-# INLINE debug #-} + +-- | Removes all html tags from a given html text +-- +-- >>> stripTags "This is Bold" +-- "This is Bold" +stripTags :: Text -> Text +stripTags "" = "" +stripTags html | Text.head html == '<' = stripTags (Text.drop 1 (Text.dropWhile (/= '>') (Text.tail html))) +stripTags html = let (a, b) = Text.splitAt 1 html in a <> stripTags b