jon.recoil.org

Source file html_shell.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(* Page shell interface and registry. *)

module Html = Tyxml.Html

type page_data = {
  url : Odoc_document.Url.Path.t;
  header : Html_types.flow5_without_header_footer Html.elt list;
  preamble : Html_types.flow5_without_header_footer Html.elt list;
  content : Html_types.div_content Html.elt list;
  breadcrumbs : Types.breadcrumbs;
  toc : Types.toc list;
  sidebar : Html_types.div_content Html.elt list option;
  sidebar_data : Odoc_document.Sidebar.t option;
  uses_katex : bool;
  source_anchor : string option;
  resources : Odoc_extension_registry.resource list;
  assets : Odoc_extension_registry.asset list;
  children : Odoc_document.Renderer.page list;
}

type src_page_data = {
  url : Odoc_document.Url.Path.t;
  header : Html_types.flow5_without_header_footer Html.elt list;
  breadcrumbs : Types.breadcrumbs;
  sidebar : Html_types.div_content Html.elt list option;
  sidebar_data : Odoc_document.Sidebar.t option;
  title : string;
  content : Html_types.div_content Html.elt list;
}

module type S = sig
  val name : string
  val make : config:Config.t -> page_data -> Odoc_document.Renderer.page
  val make_src : config:Config.t -> src_page_data -> Odoc_document.Renderer.page
end

(* Registry *)

let shells : (string, (module S)) Hashtbl.t = Hashtbl.create 4

let register (module Shell : S) =
  Hashtbl.replace shells Shell.name (module Shell : S)

let find name = Hashtbl.find_opt shells name

let list_shells () =
  Hashtbl.fold (fun name _ acc -> name :: acc) shells []
  |> List.sort String.compare

let default () =
  match Hashtbl.find_opt shells "default" with
  | Some shell -> shell
  | None -> failwith "No default shell registered"