jespresso-1.0: Extract all JavaScript from an HTML page and consolidate it in one script.

Safe HaskellNone
LanguageHaskell2010

Text.Html.Consolidate

Contents

Description

Extraction and consolidation of JavaScript code in an HTML page.

Synopsis

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

initialConsState Source

Arguments

:: 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

renderHTML :: ConsState -> TArr XmlTree XmlTree -> IO String Source

A wrapper around hxt to pretty print html out of the arrow

data ConsState Source

Consolidation state