OCaml HTML5 parser/serialiser based on Python's JustHTML
1(** Interactive element nesting checker.
2
3 Validates that interactive elements are not nested in ways that violate
4 HTML5 specifications. This checker tracks ancestor elements and ensures
5 that prohibited nesting patterns are detected and reported.
6
7 {2 Validation Rules}
8
9 The checker enforces the following prohibited nesting relationships:
10
11 {3 Self-nesting Restrictions}
12
13 These elements cannot be nested inside themselves:
14 - [form] cannot contain [form]
15 - [progress] cannot contain [progress]
16 - [meter] cannot contain [meter]
17 - [dfn] cannot contain [dfn]
18 - [noscript] cannot contain [noscript]
19 - [label] cannot contain [label]
20
21 {3 Structural Element Restrictions}
22
23 - [header] cannot be inside [header], [footer], or [address]
24 - [footer] cannot be inside [header], [footer], or [address]
25 - [address] cannot contain [header], [footer], [article], [section],
26 [nav], or heading elements ([h1]-[h6])
27
28 {3 Interactive Content Restrictions}
29
30 Interactive elements cannot be descendants of [a] (with [href]) or
31 [button]:
32
33 - [a] (when it has [href]) cannot be inside [a] or [button]
34 - [button] cannot be inside [a] or [button]
35 - [details] cannot be inside [a] or [button]
36 - [embed] cannot be inside [a] or [button]
37 - [iframe] cannot be inside [a] or [button]
38 - [label] cannot be inside [a] or [button]
39 - [select] cannot be inside [a] or [button]
40 - [textarea] cannot be inside [a] or [button]
41 - [audio] (with [controls]) cannot be inside [a] or [button]
42 - [video] (with [controls]) cannot be inside [a] or [button]
43 - [input] (except [type=hidden]) cannot be inside [a] or [button]
44 - [img] (with [usemap]) cannot be inside [a] or [button]
45 - [object] (with [usemap]) cannot be inside [a] or [button]
46
47 {3 Table Cell Restrictions}
48
49 - [dt] and [th] cannot contain [header], [footer], [article], [section],
50 [nav], heading elements ([h1]-[h6]), or [hgroup]
51
52 {3 Other Restrictions}
53
54 - [caption] cannot contain [table]
55 - [area] must have a [map] ancestor
56
57 {2 Implementation Details}
58
59 The checker uses a bitmask-based approach to efficiently track ancestor
60 elements. Each "special" ancestor element has a corresponding bit in the
61 ancestor mask. As elements are opened and closed during traversal, the
62 mask is updated to reflect the current ancestor context.
63
64 When an element is encountered, the checker:
65 1. Computes which ancestors would be prohibited for this element
66 2. Checks if any of those prohibited ancestors are present in the
67 current ancestor mask
68 3. Reports errors for any violations found
69 4. Updates the ancestor mask to include the current element (if it's
70 a special ancestor)
71
72 @see <https://html.spec.whatwg.org/multipage/dom.html#content-models>
73 HTML5 specification: Content models
74*)
75
76val checker : Checker.t
77(** [checker] is a checker instance for validating element nesting rules. *)