Safe Haskell | None |
---|---|
Language | Haskell2010 |
Extraction and consolidation of JavaScript code in an HTML page.
- consolidate :: String -> Maybe URI -> IO String
- extract :: String -> Maybe URI -> IO (JavaScript ())
- extractPretty :: String -> Maybe URI -> IO String
- type TArr a b = IOStateArrow ConsState a b
- consolidateArr :: TArr XmlTree XmlTree
- extractJSArr :: TArr XmlTree (XmlTree, JavaScript ())
- initialConsState :: Bool -> Maybe URI -> [Cookie] -> ConsState
- insertJSArr :: TArr (XmlTree, JavaScript a) XmlTree
- parseHTML :: String -> Maybe URI -> TArr a XmlTree
- renderHTML :: ConsState -> TArr XmlTree XmlTree -> IO String
- data ConsState
Simple API
consolidate :: String -> Maybe URI -> IO String Source
Takes an HTML page source as a string and an optional base URI (for resolving relative URI's) and produces an HTML page with all the scripts consolidated in one inline script element.
extract :: String -> Maybe URI -> IO (JavaScript ()) Source
Extacts all JavaScript code in the given HTML page source as a single program. Takes an optional base URI for resolving relative URI's.
extractPretty :: String -> Maybe URI -> IO String Source
Extacts and pretty-prints all JavaScript code in the given HTML page source as a single program. Takes an optional base URI for resolving relative URI's.
extractPretty s muri = liftM (show . prettyPrint) $ extract s muri
Advanced arrow-based API
type TArr a b = IOStateArrow ConsState a b Source
Our XML transformation arrow type
consolidateArr :: TArr XmlTree XmlTree Source
The consolidation function with an arrow interface.
consolidateArr = extractJSArr >>> insertJSArr
extractJSArr :: TArr XmlTree (XmlTree, JavaScript ()) Source
Extracts all JavaScript from HTML. There shouldn't be any JavaScript in the resulting XmlTree
:: Bool | Whether to ignore errors (parse errors, resource not found etc.) |
-> Maybe URI | base URI |
-> [Cookie] | Cookies |
-> ConsState |
A constructor function for making an initial consolidation state (needed for running the arrows in the advanced API). Example usage:
runXIOState (initialState $ initialConsState ignoreErrors muri []) $ someArrow
insertJSArr :: TArr (XmlTree, JavaScript a) XmlTree Source
Inserts JavaScript at the end of the HTML body.
parseHTML :: String -> Maybe URI -> TArr a XmlTree Source
A wrapper around the hxt parser with commonly used arguments