4 (* HTML simulator (first in its kind) *)
10 | `DIV of int * string option * html_tag
13 type html_msg = [ `Error of html_tag | `Msg of html_tag ]
15 type logger_fun = ?append_NL:bool -> html_msg -> unit
17 let rec string_of_html_tag =
19 let indent_str = String.make indent ' ' in
23 String.concat ("\n" ^ indent_str) (List.map (aux indent) msgs)
24 | `BR -> "\n" ^ indent_str
25 | `DIV (local_indent, _, tag) ->
26 "\n" ^ indent_str ^ aux (indent + local_indent) tag
30 let string_of_html_msg = function
31 | `Error tag -> "Error: " ^ string_of_html_tag tag
32 | `Msg tag -> string_of_html_tag tag
34 let rec html_of_html_tag = function
37 sprintf "<ul>\n%s\n</ul>"
40 (fun msg -> sprintf "<li>%s</li>" (html_of_html_tag msg))
43 | `DIV (indent, color, tag) ->
44 sprintf "<div style=\"%smargin-left:%fcm\">\n%s\n</div>"
45 (match color with None -> "" | Some color -> "color: " ^ color ^ "; ")
46 (float_of_int indent *. 0.5)
47 (html_of_html_tag tag)
49 let html_of_html_msg =
51 | `Error tag -> "<b>Error: " ^ html_of_html_tag tag ^ "</b>"
52 | `Msg tag -> html_of_html_tag tag
54 let log_callbacks = ref []
56 let register_log_callback logger_fun =
57 log_callbacks := !log_callbacks @ [ logger_fun ]
59 let log ?append_NL html_msg =
60 List.iter (fun logger_fun -> logger_fun ?append_NL html_msg) !log_callbacks