hquery-0.1.0.1: A query language for transforming HTML5

Safe HaskellNone

Text.Hquery.Utils

Contents

Description

This module exports various useful utility functions for working with XmlHtml Nodes. For example, the equality operator on Node does a structural comparison of the nodes. However, this is not entirely useful, since transformed nodes may be equal but e.g. have their attributes in a different order in the list. Among other things, this module defines an EqNode type which has an Eq instance that does semantic equality instead of structural equality.

Synopsis

Types

newtype EqNode Source

Constructors

EqNode Node 

Instances

Functions

Equality

attrsEq :: [(Text, Text)] -> [(Text, Text)] -> BoolSource

Test a list of attributes for equality. This has special handling for the class attribute, so that the order in which the classes are applied to the node doesn't matter. Additionally, the oder of the attributes in either list is also ignored.

nodeEq :: Node -> Node -> BoolSource

A top level semantic node equality funciton.

Utility

stripWhitespaceNodes :: Node -> Maybe NodeSource

Strip nodes that contain only whitespace. This can be useful when doing equality comparisons of trees (e.g. in testing). XmlHtml keeps all whitespace, which can cause structural equality differences in trees which were produced programattically vs. hand written and nicely formatted trees.