OCaml HTML5 parser/serialiser based on Python's JustHTML
1(** Debug utility for testing individual HTML files against the validator *)
2
3let () =
4 if Array.length Sys.argv < 2 then begin
5 Printf.printf "Usage: debug_validator <html-file>\n";
6 exit 1
7 end;
8
9 let path = Sys.argv.(1) in
10 let ic = open_in path in
11 let content = really_input_string ic (in_channel_length ic) in
12 close_in ic;
13
14 Printf.printf "=== Checking: %s ===\n\n" path;
15 Printf.printf "Input (%d bytes):\n%s\n\n" (String.length content) content;
16
17 let reader = Bytesrw.Bytes.Reader.of_string content in
18 let result = Htmlrw_check.check ~collect_parse_errors:true ~system_id:path reader in
19
20 let errors = Htmlrw_check.errors result in
21 let warnings = Htmlrw_check.warnings result in
22
23 Printf.printf "=== Results ===\n";
24 Printf.printf "Errors: %d\n" (List.length errors);
25 List.iter (fun msg ->
26 Printf.printf " [ERROR] %s\n" msg.Htmlrw_check.text;
27 (match msg.Htmlrw_check.location with
28 | Some loc -> Printf.printf " at line %d, col %d\n" loc.line loc.column
29 | None -> ())
30 ) errors;
31
32 Printf.printf "Warnings: %d\n" (List.length warnings);
33 List.iter (fun msg ->
34 Printf.printf " [WARN] %s\n" msg.Htmlrw_check.text;
35 (match msg.Htmlrw_check.location with
36 | Some loc -> Printf.printf " at line %d, col %d\n" loc.line loc.column
37 | None -> ())
38 ) warnings;
39
40 Printf.printf "\n=== Formatted Output ===\n";
41 Printf.printf "%s\n" (Htmlrw_check.to_text result)