OCaml HTML5 parser/serialiser based on Python's JustHTML
1open Content_category
2open Content_model
3open Attr_spec
4
5let details =
6 Element_spec.make ~name:"details"
7 ~categories:[ Flow; Sectioning; Palpable; Interactive ]
8 ~content_model:
9 (Sequence [ Elements [ "summary" ]; Zero_or_more (Categories [ Flow ]) ])
10 ~attrs:[ make "open" ~datatype:"boolean" () ] ()
11
12let summary =
13 Element_spec.make ~name:"summary"
14 ~categories:[]
15 ~content_model:
16 (Choice [ Categories [ Phrasing ]; Categories [ Heading ] ])
17 ~permitted_parents:[ "details" ]
18 ~attrs:[] ()
19
20let dialog =
21 Element_spec.make ~name:"dialog"
22 ~categories:[ Flow; Sectioning ]
23 ~content_model:(Categories [ Flow ])
24 ~attrs:[ make "open" ~datatype:"boolean" () ] ~implicit_aria_role:"dialog" ()
25
26let script =
27 Element_spec.make ~name:"script"
28 ~categories:[ Metadata; Flow; Phrasing; Script_supporting ]
29 ~content_model:Text
30 ~attrs:
31 [
32 make "src" ~datatype:"url" ();
33 make "type" ();
34 make "nomodule" ~datatype:"boolean" ();
35 make "async" ~datatype:"boolean" ();
36 make "defer" ~datatype:"boolean" ();
37 make "crossorigin" ~datatype:"crossorigin" ();
38 make "integrity" ~datatype:"integrity" ();
39 make "referrerpolicy" ~datatype:"referrer" ();
40 make "blocking" ();
41 make "fetchpriority" ~datatype:"fetchpriority" ();
42 ]
43 ()
44
45let noscript =
46 Element_spec.make ~name:"noscript"
47 ~categories:[ Metadata; Flow; Phrasing ]
48 ~content_model:
49 (Choice
50 [
51 (* In head: link, style, meta *)
52 Categories [ Metadata ];
53 (* In body: transparent, but no noscript descendants *)
54 Transparent;
55 ])
56 ~prohibited_ancestors:[ "noscript" ]
57 ~attrs:[] ()
58
59let template =
60 Element_spec.make ~name:"template"
61 ~categories:[ Metadata; Flow; Phrasing; Script_supporting ]
62 ~content_model:Nothing
63 ~attrs:[] ()
64
65let slot =
66 Element_spec.make ~name:"slot"
67 ~categories:[ Flow; Phrasing ]
68 ~content_model:Transparent
69 ~attrs:[ make "name" () ] ()
70
71let canvas =
72 Element_spec.make ~name:"canvas"
73 ~categories:[ Flow; Phrasing; Embedded; Palpable ]
74 ~content_model:Transparent
75 ~attrs:
76 [
77 make "width" ~datatype:"integer" ();
78 make "height" ~datatype:"integer" ();
79 ]
80 ()
81
82let all = [ details; summary; dialog; script; noscript; template; slot; canvas ]