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

Safe HaskellNone
LanguageHaskell2010

Text.Html.Consolidate

Contents

Description

Implements 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 String Source

Extacts and pretty-print all the JavaScript code in the given HTML page source as a single program. Takes an optional base URI for resolving relative URI's.

Advanced arrow-based API

type TArr a b = IOStateArrow ConsState a b Source

Our XML transformation arrow type

consolidateArr :: TArr XmlTree XmlTree Source

Main normalization arrow. Factored into extractJS and insertJS to allow custom transformation of JavaScript inbetween.

extractJSArr :: TArr XmlTree (XmlTree, String) Source

Extracts all the 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)

insertJSArr :: TArr (XmlTree, String) 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