In [1]:
module Tyxml_html = Html5
module Html5 = Html5.M
Out[1]:
Out[1]:
Display output as html
In [2]:
let string_of_html h =
let b = Buffer.create 16 in
Tyxml_html.P.print_list ~output:(Buffer.add_string b) h;
Buffer.contents b
let html x = Iocaml.display "text/html" (string_of_html x)
Out[2]:
Out[2]:
In [3]:
html <:html5list< <b>Hello <i>world</i></b> >>
Out[3]:
In [4]:
html <:html5list<
<table>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>d</td>
</tr>
</table>
>>
Out[4]:
In [5]:
let table f x =
let row = List.map (fun x -> <:html5< <td>$str:f x$</td> >>) in
let rows = List.map (fun x -> <:html5< <tr>$list:row x$</tr> >>) in
<:html5< <table>$list:rows x$</table> >>
Out[5]:
In [6]:
html [table string_of_int
[ [0;1;2];
[3;4;5];
]
]
Out[6]:
In [7]:
module Tyxml_svg = Svg
module Svg = Svg.M
Out[7]:
Out[7]:
In [8]:
let string_of_svg h =
let b = Buffer.create 16 in
Tyxml_svg.P.print_list ~output:(Buffer.add_string b) h;
Buffer.contents b
let svg x = Iocaml.display "text/html" (string_of_svg x)
Out[8]:
Out[8]:
In [9]:
svg <:svglist< <svg width="100" height="100"><circle r="40" cx="50" cy="50" /></svg> >>
Out[9]: