5 (* HTML simulator (first in its kind) *)
11 | `DIV of int * string option * html_tag
14 type html_msg = [ `Error of html_tag | `Msg of html_tag ]
16 type logger_fun = ?append_NL:bool -> html_msg -> unit
18 let rec string_of_html_tag =
20 let indent_str = String.make indent ' ' in
24 String.concat ("\n" ^ indent_str) (List.map (aux indent) msgs)
25 | `BR -> "\n" ^ indent_str
26 | `DIV (local_indent, _, tag) ->
27 "\n" ^ indent_str ^ aux (indent + local_indent) tag
31 let string_of_html_msg = function
32 | `Error tag -> "Error: " ^ string_of_html_tag tag
33 | `Msg tag -> string_of_html_tag tag
35 let rec html_of_html_tag = function
38 sprintf "<ul>\n%s\n</ul>"
41 (fun msg -> sprintf "<li>%s</li>" (html_of_html_tag msg))
44 | `DIV (indent, color, tag) ->
45 sprintf "<div style=\"%smargin-left:%fcm\">\n%s\n</div>"
46 (match color with None -> "" | Some color -> "color: " ^ color ^ "; ")
47 (float_of_int indent *. 0.5)
48 (html_of_html_tag tag)
50 let html_of_html_msg =
52 | `Error tag -> "<b>Error: " ^ html_of_html_tag tag ^ "</b>"
53 | `Msg tag -> html_of_html_tag tag
55 let log_callbacks = ref []
57 let register_log_callback logger_fun =
58 log_callbacks := !log_callbacks @ [ logger_fun ]
60 let log ?append_NL html_msg =
61 List.iter (fun logger_fun -> logger_fun ?append_NL html_msg) !log_callbacks