Open Drup opened 8 years ago
Well, this isn't really due to the PPX primarily – it is due to irregularities in the TyXML interface. However, the PPX might have an opportunity to hackily coerce its way through such situations, due to having some reflection available. It does seem a bit complicated, since we would want the coercion to be compile-time for best effect.
I don't see how you would do anything about it in a composable way. Consider:
let mytitle = [%html5 "<title>A Fabulous Web Page</title>" ]
let myhead = [%html5
"<head>"mytitle"<meta bla/>"mytitle"</head>"
]
You need name resolution and typechecking to know that this is incorrect. You couldn't even generate tyxml code for that, without typechecking. This is precisely why tyxml is irregular there.
It's not a big problem in practice, though, you can just inline the title
tag and use the antiquotation on the pcdata.
Yes, I think making this fully composable without inserting run-time coercions isn't going to happen with a PPX.
I think this should be made to work, if possible, since you made the change to how antiquotations are inserted:
let%html to_ocaml = "<li><a href='ocaml.org'>OCaml</a></li>"
let%html to_tyxml = "<li><a href='ocsigen.org/tyxml'>TyXML</a></li>"
let%html links = "<ul>" to_ocaml "<li>foo</li>" to_tyxml "</ul>"
Looking into it.
Ok,
let%html links = "<ul>" [to_ocaml] "<li>foo</li>" [to_tyxml] "</ul>"
Here is an example of something that doesn't work:
Error message by markup: "head element must have exactly one title child element".
I don't know how solvable it is. It sounds tricky.