ocsigen / ocsigen/tyxml

Converting `[\Svg] Tyxml_svg.elt` to `[\Svg] Js_of_ocaml_tyxml.Tyxml_js.Html.elt`

Open
#323 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
179
Forks
63
Avg merge
5h
Merged PRs (30d)
22

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Tyxml_svg.elt type, the Tyxml_js module from Js_of_ocaml_tyxml, and the To_dom.of_* conversion functions described in the issue. Document the supported conversions in a diagram and add a small typed SVG-in-HTML example, making clear what the terminal and web interfaces should use.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.