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

Safe HaskellNone

Text.Html.Consolidate

Contents

Description

Implements extraction and consolidation of JavaScript code in an HTML page.

Synopsis

Simple API

consolidate :: String -> Maybe URI -> IO StringSource

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 StringSource

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 bSource

Our XML transformation arrow type

consolidateArr :: TArr XmlTree XmlTreeSource

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

initialConsStateSource

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) XmlTreeSource

Inserts JavaScript at the end of the HTML body.

parseHTML :: String -> Maybe URI -> TArr a XmlTreeSource

A wrapper around the hxt parser with commonly used arguments

renderHTML :: ConsState -> TArr XmlTree XmlTree -> IO StringSource

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