OCaml HTML5 parser/serialiser based on Python's JustHTML
1(** Typed error codes for HTML5 validation messages. 2 3 This module defines a comprehensive variant type for all validation errors, 4 ensuring exact message matching with the Nu HTML Validator test suite. *) 5 6(** Severity level of a validation message *) 7type severity = Error | Warning | Info 8 9(** Typed error codes with associated data *) 10type t = 11 (* Attribute Errors *) 12 | Attr_not_allowed_on_element of { attr: string; element: string } 13 | Attr_not_allowed_here of { attr: string } 14 | Attr_not_allowed_when of { attr: string; element: string; condition: string } 15 | Missing_required_attr of { element: string; attr: string } 16 | Missing_required_attr_one_of of { element: string; attrs: string list } 17 | Bad_attr_value of { element: string; attr: string; value: string; reason: string } 18 | Bad_attr_value_generic of { message: string } 19 | Duplicate_id of { id: string } 20 | Data_attr_invalid_name of { reason: string } 21 | Data_attr_uppercase 22 23 (* Element Errors *) 24 | Obsolete_element of { element: string; suggestion: string } 25 | Obsolete_attr of { element: string; attr: string; suggestion: string option } 26 | Element_not_allowed_as_child of { child: string; parent: string } 27 | Element_must_not_be_descendant of { element: string; attr: string option; ancestor: string } 28 | Missing_required_child of { parent: string; child: string } 29 | Missing_required_child_one_of of { parent: string; children: string list } 30 | Missing_required_child_generic of { parent: string } 31 | Element_must_not_be_empty of { element: string } 32 | Stray_start_tag of { tag: string } 33 | Stray_end_tag of { tag: string } 34 | End_tag_for_void_element of { tag: string } 35 | Self_closing_non_void 36 | Text_not_allowed of { parent: string } 37 38 (* Child Restrictions *) 39 | Div_child_of_dl_bad_role 40 | Li_bad_role_in_menu 41 | Li_bad_role_in_tablist 42 | Li_bad_role_in_list 43 44 (* ARIA Errors *) 45 | Unnecessary_role of { role: string; element: string; reason: string } 46 | Bad_role of { element: string; role: string } 47 | Aria_must_not_be_specified of { attr: string; element: string; condition: string } 48 | Aria_must_not_be_used of { attr: string; element: string; condition: string } 49 | Aria_should_not_be_used of { attr: string; role: string } 50 | Img_empty_alt_with_role 51 | Checkbox_button_needs_aria_pressed 52 | Tab_without_tabpanel 53 | Multiple_main_visible 54 | Discarding_unrecognized_role of { token: string } 55 56 (* Required Attribute/Element Conditions *) 57 | Img_missing_alt 58 | Img_missing_src_or_srcset 59 | Option_empty_without_label 60 | Bdo_missing_dir 61 | Bdo_dir_auto 62 | Base_missing_href_or_target 63 | Base_after_link_script 64 | Link_missing_href 65 | Link_as_requires_preload 66 | Link_imagesrcset_requires_as_image 67 | Img_ismap_needs_a_href 68 | Sizes_without_srcset 69 | Imagesizes_without_imagesrcset 70 | Srcset_w_without_sizes 71 | Source_missing_srcset 72 | Source_needs_media_or_type 73 | Picture_missing_img 74 | Map_id_name_mismatch 75 | List_attr_requires_datalist 76 | Label_too_many_labelable 77 | Label_for_id_mismatch 78 | Input_value_constraint of { constraint_type: string } 79 | Summary_missing_role 80 | Summary_missing_attrs 81 | Autocomplete_webauthn_on_select 82 | Commandfor_invalid_target 83 84 (* Parse Errors *) 85 | Forbidden_codepoint of { codepoint: int } 86 | Char_ref_control of { codepoint: int } 87 | Char_ref_non_char of { codepoint: int; astral: bool } 88 | Char_ref_unassigned 89 | Char_ref_zero 90 | Char_ref_out_of_range 91 | Numeric_char_ref_carriage_return 92 | End_of_file_with_open_elements 93 | No_element_in_scope of { tag: string } 94 | End_tag_implied_open_elements of { tag: string } 95 | Start_tag_in_table of { tag: string } 96 | Bad_start_tag_in of { tag: string; context: string } 97 98 (* Table Errors *) 99 | Table_row_no_cells of { row: int } 100 | Table_cell_overlap 101 | Table_cell_spans_rowgroup 102 | Table_column_no_cells of { column: int; element: string } 103 104 (* Language/Internationalization *) 105 | Missing_lang_attr 106 | Wrong_lang of { detected: string; declared: string; suggested: string } 107 | Missing_dir_rtl of { language: string } 108 | Wrong_dir of { language: string; declared: string } 109 | Xml_lang_without_lang 110 | Xml_lang_lang_mismatch 111 112 (* Unicode Normalization *) 113 | Not_nfc of { replacement: string } 114 115 (* Multiple h1 *) 116 | Multiple_h1 117 | Multiple_autofocus 118 119 (* Import Maps *) 120 | Importmap_invalid_json 121 | Importmap_invalid_root 122 | Importmap_imports_not_object 123 | Importmap_empty_key 124 | Importmap_non_string_value 125 | Importmap_key_trailing_slash 126 | Importmap_scopes_not_object 127 | Importmap_scopes_values_not_object 128 | Importmap_scopes_invalid_url 129 130 (* Style Element *) 131 | Style_type_invalid 132 133 (* Headingoffset *) 134 | Headingoffset_invalid 135 136 (* Media Attribute *) 137 | Media_empty 138 | Media_all 139 140 (* SVG/MathML specific *) 141 | Svg_deprecated_attr of { attr: string; element: string } 142 | Missing_required_svg_attr of { element: string; attr: string } 143 144 (* Generic/Fallback *) 145 | Generic of { message: string } 146 147(** Get the severity level for an error code *) 148val severity : t -> severity 149 150(** Get a short code string for categorization *) 151val code_string : t -> string 152 153(** Convert error code to exact Nu validator message string *) 154val to_message : t -> string 155 156(** Format a string with curly quotes *) 157val q : string -> string