transforming xhtml attributes

Chris Dornan chris at
Fri May 11 22:49:53 CEST 2012

I am proposing to extend the xhtml package slightly to better support
attribute munging.
Currently you would use (!) to add a bunch of attributes to an element,
                b1 = button noHtml ! [name "go", value "go"]
The problem, as pointed out by mistuke[1]  is that there is no way to safely
add attributes as this could result in an attribute being bound ambiguously
and illegally [2] thus:
                b2 = b1 ! [value "oops"]
Apparently this can lead Haddock to generate illegal (X)HTML [1].
My proposed solution is to add a new CHANGEATTRS class with the overloaded
                changeAttrs :: CHANGEATTRS a => a -> ([HtmlAttr] ->
[HtmlAttr]) -> a
and to export a function for analysing the (abstract) HtmlAttr type:
                htmlAttrPair :: HtmlAttr -> (String, String)
CHANGEATTRS/changeAttrs/htmlAttrPair works just like ADDATTRS/(!) except
that the attributes can be analysed and transformed. 
                extend_name :: Html -> Html
                extend_name h = h `changeAttrs` map f
                        f a  = case htmlAttrPair a of
                                 ("name",nm) -> name $ "foo_" ++ nm
                                 _           -> a
Finally, I have an embarrassing confession to make -- I forgot that I should
be getting the changes reviewed here -- even for such a modest widening of
the API -- and have already put out
3000.2.1 with these additions onto Hackage!
Comments and feedback welcome though,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list