OCaml HTML5 parser/serialiser based on Python's JustHTML
1type t = {
2 name : string;
3 void : bool;
4 categories : Content_category.t list;
5 content_model : Content_model.t;
6 permitted_parents : string list option;
7 prohibited_ancestors : string list;
8 tag_omission : bool;
9 attrs : Attr_spec.t list;
10 implicit_aria_role : string option;
11}
12
13let make ~name ?(void = false) ?(categories = [])
14 ?(content_model = Content_model.Nothing) ?permitted_parents
15 ?(prohibited_ancestors = []) ?(tag_omission = false) ?(attrs = [])
16 ?implicit_aria_role () =
17 {
18 name;
19 void;
20 categories;
21 content_model;
22 permitted_parents;
23 prohibited_ancestors;
24 tag_omission;
25 attrs;
26 implicit_aria_role;
27 }
28
29let is_void t = t.void
30
31let has_category t category = List.mem category t.categories
32
33let pp fmt t =
34 Format.fprintf fmt "@[<v 2>{ name = %S;@ void = %b;@ " t.name t.void;
35 Format.fprintf fmt "categories = [%a];@ "
36 (Format.pp_print_list
37 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
38 Content_category.pp)
39 t.categories;
40 Format.fprintf fmt "content_model = %a;@ " Content_model.pp t.content_model;
41 (match t.permitted_parents with
42 | None -> Format.fprintf fmt "permitted_parents = None;@ "
43 | Some parents ->
44 Format.fprintf fmt "permitted_parents = Some [%a];@ "
45 (Format.pp_print_list
46 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
47 (fun fmt s -> Format.fprintf fmt "%S" s))
48 parents);
49 Format.fprintf fmt "prohibited_ancestors = [%a];@ "
50 (Format.pp_print_list
51 ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
52 (fun fmt s -> Format.fprintf fmt "%S" s))
53 t.prohibited_ancestors;
54 Format.fprintf fmt "tag_omission = %b;@ " t.tag_omission;
55 Format.fprintf fmt "attrs = [%a];@ "
56 (Format.pp_print_list
57 ~pp_sep:(fun fmt () -> Format.fprintf fmt ";@ ")
58 Attr_spec.pp)
59 t.attrs;
60 (match t.implicit_aria_role with
61 | None -> Format.fprintf fmt "implicit_aria_role = None }@]"
62 | Some role -> Format.fprintf fmt "implicit_aria_role = Some %S }@]" role)