OCaml HTML5 parser/serialiser based on Python's JustHTML
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: MIT
4 ---------------------------------------------------------------------------*)
5
6(** Entry point for the standalone JavaScript build.
7
8 This module is compiled to [htmlrw.js] and automatically registers
9 the validation API on [window.html5rw] when loaded.
10
11 {2 Browser Usage}
12
13 {v
14 <script src="htmlrw.js"></script>
15 <script>
16 // API is available immediately after loading
17 const result = html5rw.validateElement(document.body);
18
19 if (result.errorCount > 0) {
20 console.log("Found", result.errorCount, "errors");
21
22 // Show the warning panel
23 html5rw.showPanel(result);
24 }
25 </script>
26 v}
27
28 {2 Module Bundler Usage}
29
30 If using a bundler that supports CommonJS or ES modules, you can
31 import the module instead:
32
33 {v
34 import { validateElement, showPanel } from './htmlrw.js';
35
36 const result = validateElement(document.body);
37 if (result.hasErrors) {
38 showPanel(result);
39 }
40 v}
41
42 The module exports are set up to work with both import styles.
43
44 {2 API Reference}
45
46 See {!Htmlrw_js} for the full API documentation. The JavaScript API
47 mirrors the OCaml API with camelCase naming:
48
49 - [html5rw.validateString(html)] - Validate an HTML string
50 - [html5rw.validateElement(el)] - Validate a DOM element
51 - [html5rw.validateAndAnnotate(el, config?)] - Validate and annotate
52 - [html5rw.showPanel(result, config?)] - Show the warning panel
53 - [html5rw.hidePanel()] - Hide the warning panel
54 - [html5rw.clearAnnotations(el)] - Clear annotations from an element *)
55
56(* This module has no values; its side effect is registering the API *)