Skip to content

Commit

Permalink
Added stripTags to HaskellSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Oct 4, 2020
1 parent 294144c commit c0e1582
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions IHP/HaskellSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module IHP.HaskellSupport (
, todayIsWeekend
, debug
, includes
, stripTags
) where

import ClassyPrelude
Expand All @@ -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 |>
Expand Down Expand Up @@ -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 <b>Bold</b>"
-- "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

0 comments on commit c0e1582

Please sign in to comment.