{-# LANGUAGE OverloadedStrings #-}
module Readability
(
Article (..),
fromByteString,
fromDocument,
fromFile,
fromText,
)
where
import Data.ByteString.Lazy (ByteString)
import Data.Text.Lazy (Text)
import Readability.Internal as I
import Readability.Types
import qualified Text.HTML.DOM as DOM
import Text.XML (Document)
fromDocument :: Document -> Maybe Article
fromDocument = fromDocument' strictSettings
fromDocument' :: Settings -> Document -> Maybe Article
fromDocument' s d = Article <$> I.summary s d
fromByteString :: ByteString -> Maybe Article
fromByteString = fromDocument . DOM.parseLBS
fromFile :: FilePath -> IO (Maybe Article)
fromFile f = fromDocument <$> DOM.readFile f
fromText :: Text -> Maybe Article
fromText = fromDocument . DOM.parseLT
strictSettings :: Settings
strictSettings =
Settings
{ reRemoveAttributes = (`elem` ["class"])
}