Folks,

 

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

 

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

 

                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

                      where

                        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,

 

Chris

 

[1] https://github.com/haskell/xhtml/issues/2

[2] http://www.w3.org/WAI/GL/WCAG20-TECHS/H94.html