TyXML is a library for building statically correct HTML5 and SVG documents:
open Tyxml
let to_ocaml = Html.(a ~a:[a_href "ocaml.org"] [txt "OCaml!"])
Tyxml can also be used with the standard HTML syntax, using the PPX:
open Tyxml
let%html to_ocaml = "<a href='ocaml.org'>OCaml!</a>"
Finally, TyXML can be used with Reason's JSX syntax:
open Tyxml;
let to_reason = <a href="reasonml.github.io/"> "Reason!" </a>
TyXML provides a set of combinators which use the OCaml type system to ensure the validity of the generated document. TyXML can be used on a wide variety of context, either to produce textual documents, to manipulate the DOM tree using Js_of_ocaml, build virtual DOM with virtual-dom, or for tierless web programming with Eliom.
The documentation can be consulted on the TyXML website. Examples are available in the examples directory.
TyXML is available in OPAM:
opam install tyxml
To install the PPX:
opam install tyxml-ppx
To install the JSX:
opam install tyxml-jsx