Merge classes when several class attributes given
I think it would be interesting to be able to put several class attributes.
let popup ?(a = []) content =
let box = D.div ~a:(a_class ["popup"]::a) content in
...
Here my function creates a widget popup. All popups have class "popup". But I'd like to make possible for user to customize the widget by adding any attribute he wants.
With the current version of tyxml, the code below does not work if a contains a class ...
How does it "not work" ? If it crashes or something, I'm pretty sure it's related to the implementation of the D module, because nothing in tyxml do anything about double attributes.
However, I went and check, and having multiple attributes (and class in particular) is indeed forbidden by the standard, so we could do something about that .... I'm not sure how.
In the tyxml functor, we know that attribute lists are indeed of type list (it's not a Wrap.tlist as with attributes), but we don't know anything about the attrib type, so we can't simplify ourselves, it needs to be done by the module implementing Xml, probably in the leaf and node functions.
In eliom, the relevant pieces are: https://github.com/ocsigen/eliom/blob/master/src/lib/eliom_lib_base.shared.ml#L119 https://github.com/ocsigen/eliom/blob/master/src/lib/eliom_content_core.server.ml#L251-L252
I took some time to investigate this a little bit (because this is really annoying). Actually, the problems happens only on client side. When the element is generated on server side, I don't know by what magic, classes are successfully merged and everything goes well. But on client side, one class attribute is dropped. I don't know how it works on server side but may be we should do somehow the same in To_dom.