OCaml HTML5 parser/serialiser based on Python's JustHTML
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 53 lines 1.4 kB view raw
1(** Source element context validation checker. 2 Validates that source attributes are appropriate for the parent context. *) 3 4type parent_context = 5 | Picture 6 | Video 7 | Audio 8 | Other 9 10type state = { 11 mutable context_stack : parent_context list; 12} 13 14let create () = { 15 context_stack = []; 16} 17 18let reset state = 19 state.context_stack <- [] 20 21let current_context state = 22 match state.context_stack with 23 | ctx :: _ -> ctx 24 | [] -> Other 25 26let start_element state ~element collector = 27 match element.Element.tag with 28 | Tag.Html `Picture -> 29 state.context_stack <- Picture :: state.context_stack 30 | Tag.Html `Video -> 31 state.context_stack <- Video :: state.context_stack 32 | Tag.Html `Audio -> 33 state.context_stack <- Audio :: state.context_stack 34 | Tag.Html `Source -> 35 let ctx = current_context state in 36 (match ctx with 37 | Video | Audio -> 38 (* These attributes are only valid on source in picture, not audio/video *) 39 Attr_utils.check_disallowed_attrs 40 ~element:"source" ~collector ~attrs:element.raw_attrs 41 ["srcset"; "sizes"; "width"; "height"] 42 | Picture | Other -> ()) 43 | _ -> () 44 45let end_element state ~tag _collector = 46 match tag with 47 | Tag.Html (`Picture | `Video | `Audio) -> 48 (match state.context_stack with 49 | _ :: rest -> state.context_stack <- rest 50 | [] -> ()) 51 | _ -> () 52 53let checker = Checker.make ~create ~reset ~start_element ~end_element ()