Demo x-ocaml html support
The function X_ocaml_lib.output_html
provides a way to print raw html as output:
let () = X_ocaml_lib.output_html "<h1>HTML Title</h1>"
let () = X_ocaml_lib.output_html
{|<svg height="210" width="500" xmlns="http://www.w3.org/2000/svg">
<polygon points="100,10 40,198 190,78 10,78 160,198"
style="fill:yellow;stroke:darkblue;stroke-width:5"/></svg>|}
You can for example combine it with Tyxml as follows:
open Tyxml_html
let print_html t = Format.kasprintf X_ocaml_lib.output_html "%a" (pp_elt ()) t
let test =
table
@@ tr [ th [ txt "i" ]; th [ txt "i^2" ] ]
:: List.init 5 (fun i ->
tr
[
td [ txt @@ string_of_int i ];
td [ txt @@ string_of_int (i * i) ];
])
let () = print_html test
Or with graphviz, using the jsoo-graphviz
bindings to viz.js
:
let graphviz = Jsoo_graphviz.render_svg X_ocaml_lib.output_html
let () = graphviz {|digraph { rankdir="LR"; a -> b -> c }|}
The Tyxml and Jsoo_graphviz modules were loaded into the page using src-load="tyxml_graphviz.js"
(check the html source), where the file tyxml_graphviz.js
was produced by:
$ opam install tyxml
$ opam pin add https://github.com/art-w/jsoo-graphviz.git
$ opam pin add https://github.com/art-w/x-ocaml.git
$ x-ocaml tyxml jsoo-graphviz -o tyxml_graphviz.js