aboutsummaryrefslogtreecommitdiff
path: root/src/Parser/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Parser/Utils.hs')
-rw-r--r--src/Parser/Utils.hs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Parser/Utils.hs b/src/Parser/Utils.hs
index d72a1ce..98694bb 100644
--- a/src/Parser/Utils.hs
+++ b/src/Parser/Utils.hs
@@ -5,14 +5,16 @@ module Parser.Utils
, getTagAttributes
, getTagAttribute
, getTagTextAfter
+ , hasClass
) where
import Data.List (find, findIndex)
-import Data.Maybe (listToMaybe, catMaybes)
+import Data.Maybe (listToMaybe, catMaybes, isJust)
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup
+import Text.HTML.TagSoup.Match (tagOpen)
getTagsBefore :: String -> [Tag Text] -> [Tag Text]
getTagsBefore selector = takeWhile (~/= selector)
@@ -43,7 +45,15 @@ getTagTextAfter selector tags =
maybeTagAttribute :: Text -> Tag Text -> Maybe Text
maybeTagAttribute name (TagOpen _ xs) =
fmap snd . find (\(x, _) -> x == name) $ xs
-maybeTagAttribute attribute _ = Nothing
+maybeTagAttribute _ _ = Nothing
safeGetAt :: Int -> [a] -> Maybe a
safeGetAt index = listToMaybe . drop index
+
+hasClass :: Text -> Text -> Tag Text -> Bool
+hasClass selector className =
+ tagOpen ((==) selector) (isJust . find matchClass)
+ where matchClass (name, values) =
+ ( name == (T.pack "class")
+ && (isJust . find ((==) className) . T.words $ values)
+ )