module Parser.Detail ( parseDetail ) where import Data.Text (Text) import qualified Data.Text as T import Text.HTML.TagSoup import Model.Detail import Parser.Utils parseDetail :: Text -> Detail parseDetail page = let tags = parseTags page description = parseDescription tags images = getTagAttributes "" (T.pack "content") tags in Detail { description = description, images = images } parseDescription :: [Tag Text] -> Maybe Text parseDescription tags = let descriptionTags = getTagsBetween "
" "
" tags in if null descriptionTags then Nothing else let replaceBr = map (\tag -> if tag ~== "
" then TagText (T.pack "\n") else tag) in Just . T.strip . renderTags . replaceBr $ descriptionTags