+65
-1
lib/htmlrw_check/element/attr.ml
+65
-1
lib/htmlrw_check/element/attr.ml
···
784
784
let get_id attrs =
785
785
List.find_map (function `Id s -> Some s | _ -> None) attrs
786
786
787
-
(** Get class attribute *)
787
+
(** Get class attribute as raw string *)
788
788
let get_class attrs =
789
789
List.find_map (function `Class s -> Some s | _ -> None) attrs
790
+
791
+
(** Get class attribute as list of class names (space-separated) *)
792
+
let get_class_list attrs =
793
+
match get_class attrs with
794
+
| Some s -> Datatype.split_on_whitespace s
795
+
| None -> []
790
796
791
797
(** Get href attribute *)
792
798
let get_href attrs =
···
859
865
(** Get all data-* attributes *)
860
866
let get_all_data attrs =
861
867
List.filter_map (function `Data_attr (n, v) -> Some (n, v) | _ -> None) attrs
868
+
869
+
(** {2 Space-Separated Attribute List Getters} *)
870
+
871
+
(** Get rel attribute as raw string *)
872
+
let get_rel attrs =
873
+
List.find_map (function `Rel s -> Some s | _ -> None) attrs
874
+
875
+
(** Get rel attribute as list of link types (space-separated) *)
876
+
let get_rel_list attrs =
877
+
match get_rel attrs with
878
+
| Some s -> Datatype.split_on_whitespace s
879
+
| None -> []
880
+
881
+
(** Get headers attribute as raw string *)
882
+
let get_headers attrs =
883
+
List.find_map (function `Headers s -> Some s | _ -> None) attrs
884
+
885
+
(** Get headers attribute as list of IDs (space-separated) *)
886
+
let get_headers_list attrs =
887
+
match get_headers attrs with
888
+
| Some s -> Datatype.split_on_whitespace s
889
+
| None -> []
890
+
891
+
(** Get itemref attribute as raw string *)
892
+
let get_itemref attrs =
893
+
List.find_map (function `Itemref s -> Some s | _ -> None) attrs
894
+
895
+
(** Get itemref attribute as list of IDs (space-separated) *)
896
+
let get_itemref_list attrs =
897
+
match get_itemref attrs with
898
+
| Some s -> Datatype.split_on_whitespace s
899
+
| None -> []
900
+
901
+
(** Get itemprop attribute as raw string *)
902
+
let get_itemprop attrs =
903
+
List.find_map (function `Itemprop s -> Some s | _ -> None) attrs
904
+
905
+
(** Get itemprop attribute as list of property names (space-separated) *)
906
+
let get_itemprop_list attrs =
907
+
match get_itemprop attrs with
908
+
| Some s -> Datatype.split_on_whitespace s
909
+
| None -> []
910
+
911
+
(** Get itemtype attribute as raw string *)
912
+
let get_itemtype attrs =
913
+
List.find_map (function `Itemtype s -> Some s | _ -> None) attrs
914
+
915
+
(** Get itemtype attribute as list of URLs (space-separated) *)
916
+
let get_itemtype_list attrs =
917
+
match get_itemtype attrs with
918
+
| Some s -> Datatype.split_on_whitespace s
919
+
| None -> []
920
+
921
+
(** Get a specific aria-* attribute as list (for space-separated values like aria-labelledby) *)
922
+
let get_aria_list name attrs =
923
+
match get_aria name attrs with
924
+
| Some s -> Datatype.split_on_whitespace s
925
+
| None -> []
862
926
863
927
(** Find an attribute matching a predicate *)
864
928
let find f attrs =
+47
-1
lib/htmlrw_check/element/attr.mli
+47
-1
lib/htmlrw_check/element/attr.mli
···
461
461
(** [get_id attrs] extracts the id attribute value if present. *)
462
462
463
463
val get_class : t list -> string option
464
-
(** [get_class attrs] extracts the class attribute value if present. *)
464
+
(** [get_class attrs] extracts the class attribute value as a raw string. *)
465
+
466
+
val get_class_list : t list -> string list
467
+
(** [get_class_list attrs] extracts the class attribute as a list of class names.
468
+
Returns empty list if not present. Space-separated values are split. *)
465
469
466
470
val get_href : t list -> string option
467
471
(** [get_href attrs] extracts the href attribute value if present. *)
···
520
524
521
525
val get_all_data : t list -> (string * string) list
522
526
(** [get_all_data attrs] extracts all data-* attributes. *)
527
+
528
+
(** {2 Space-Separated Attribute List Getters} *)
529
+
530
+
val get_rel : t list -> string option
531
+
(** [get_rel attrs] extracts the rel attribute value as a raw string. *)
532
+
533
+
val get_rel_list : t list -> string list
534
+
(** [get_rel_list attrs] extracts the rel attribute as a list of link types.
535
+
Returns empty list if not present. Space-separated values are split. *)
536
+
537
+
val get_headers : t list -> string option
538
+
(** [get_headers attrs] extracts the headers attribute value as a raw string. *)
539
+
540
+
val get_headers_list : t list -> string list
541
+
(** [get_headers_list attrs] extracts the headers attribute as a list of IDs.
542
+
Returns empty list if not present. Space-separated values are split. *)
543
+
544
+
val get_itemref : t list -> string option
545
+
(** [get_itemref attrs] extracts the itemref attribute value as a raw string. *)
546
+
547
+
val get_itemref_list : t list -> string list
548
+
(** [get_itemref_list attrs] extracts the itemref attribute as a list of IDs.
549
+
Returns empty list if not present. Space-separated values are split. *)
550
+
551
+
val get_itemprop : t list -> string option
552
+
(** [get_itemprop attrs] extracts the itemprop attribute value as a raw string. *)
553
+
554
+
val get_itemprop_list : t list -> string list
555
+
(** [get_itemprop_list attrs] extracts the itemprop attribute as a list of property names.
556
+
Returns empty list if not present. Space-separated values are split. *)
557
+
558
+
val get_itemtype : t list -> string option
559
+
(** [get_itemtype attrs] extracts the itemtype attribute value as a raw string. *)
560
+
561
+
val get_itemtype_list : t list -> string list
562
+
(** [get_itemtype_list attrs] extracts the itemtype attribute as a list of URLs.
563
+
Returns empty list if not present. Space-separated values are split. *)
564
+
565
+
val get_aria_list : string -> t list -> string list
566
+
(** [get_aria_list name attrs] extracts a specific aria-* attribute as a list.
567
+
Useful for space-separated aria values like aria-labelledby, aria-describedby.
568
+
Returns empty list if not present. *)
523
569
524
570
val find : (t -> 'a option) -> t list -> 'a option
525
571
(** [find f attrs] finds the first attribute matching predicate [f]. *)