-
Notifications
You must be signed in to change notification settings - Fork 63
Description
I'm easily lost in the documentation of TyXML, and in particular I would really appreciate some kind of diagram showing all the conversions that can be invoked between the different types of TyXML/Js_of_ocaml/etc. So it is possible that this issue is just a documentation issue. It might also be an issue belonging to another project (maybe Js_of_ocaml_tyxml?), as I'm missing subtleties between the separation of these projects.
Here is my issue: the core of my program produces a representation of an SVG file in the type [`Svg] Tyxml_svg.elt (which is the type that comes out when I use the let%svg syntax with Tyxml openned). I have two interfaces for it, on terminal and web.
In the terminal version, I need to produce a SVG file from it. This is done easily enough with Format.fprintf fmt "%a@." (Tyxml.Svg.pp ~indent:true ()) svg.
In the web version, I use the module Tyxml_js of Js_of_ocaml_tyxml to produce my webpage, as this type is easy to manipulate and to convert into an actual webpage using one of the To_dom.of_* functions.
The issue is that I can't insert as-is my image svg : [`Svg] Tyxml_svg.elt as these types are not compatible.
I suspect that underneath, they both use Xml.elt as a representation, but that this type constraint is hidden in the module definition of Tyxml_svg (for good reasons, as not all Xml.elt are valid SVG elements). I however have the impression that no conversion function has been provided before hiding the elt type under the module signature, so we are stuck within Tyxml_svg.elt.
Maybe I am doing things in the wrong way here: do tell me if I should use other types for this usage ☺ TyXML is really useful for building typesafe SVG documents and webpages, but I still have trouble converting from types to types (which is why a recapitulating diagram would really help ☺).
When looking for similar issues online, we find several instances of people getting confused on how to incorporate SVG documents within HTML in a typed way (e.g. https://fa.caml.narkive.com/0g4ImGGn/caml-list-js-of-ocaml-and-svg ), and I think that it would be really useful to clarify how to do it properly with a small example.