• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ocaml / odoc / 2170

10 Jul 2024 02:39PM CUT coverage: 71.864% (+0.2%) from 71.668%
2170

push

github

jonludlam
fix large odoc-nav element in two columns layout

9849 of 13705 relevant lines covered (71.86%)

3514.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/html/html_fragment_json.ml
1
(* Rendering of HTML fragments together with metadata. For embedding the
2
   generated documentation in existing websites.
3
*)
4

5
module Html = Tyxml.Html
6
module Url = Odoc_document.Url
7

8
let json_of_breadcrumbs (breadcrumbs : Types.breadcrumb list) : Utils.Json.json
9
    =
10
  let breadcrumb (b : Types.breadcrumb) =
10✔
11
    `Object
19✔
12
      [
13
        ("name", `String b.name);
14
        ("href", `String b.href);
15
        ("kind", `String (Url.Path.string_of_kind b.kind));
19✔
16
      ]
17
  in
18
  let json_breadcrumbs = breadcrumbs |> List.map breadcrumb in
19
  `Array json_breadcrumbs
10✔
20

21
let json_of_toc (toc : Types.toc list) : Utils.Json.json =
22
  let rec section (s : Types.toc) =
8✔
23
    `Object
2✔
24
      [
25
        ("title", `String s.title_str);
26
        ("href", `String s.href);
27
        ("children", `Array (List.map section s.children));
2✔
28
      ]
29
  in
30
  let toc_json_list = toc |> List.map section in
31
  `Array toc_json_list
8✔
32

33
let make ~config ~preamble ~url ~breadcrumbs ~sidebar ~toc ~uses_katex
34
    ~source_anchor content children =
35
  let filename = Link.Path.as_filename ~is_flat:(Config.flat config) url in
16✔
36
  let filename = Fpath.add_ext ".json" filename in
16✔
37
  let json_to_string json = Utils.Json.to_string json in
8✔
38
  let source_anchor =
39
    match source_anchor with Some url -> `String url | None -> `Null
6✔
40
  in
41
  let json_of_html h =
42
    let htmlpp = Html.pp_elt ~indent:(Config.indent config) () in
16✔
43
    String.concat "" (List.map (Format.asprintf "%a" htmlpp) h)
16✔
44
  in
45
  let global_toc =
46
    match sidebar with
47
    | None -> `Null
16✔
48
    | Some sidebar -> `String (json_of_html sidebar)
×
49
  in
50
  let content ppf =
51
    Format.pp_print_string ppf
8✔
52
      (json_to_string
8✔
53
         (`Object
54
           [
55
             ("type", `String "documentation");
56
             ("uses_katex", `Bool uses_katex);
57
             ("breadcrumbs", json_of_breadcrumbs breadcrumbs);
8✔
58
             ("toc", json_of_toc toc);
8✔
59
             ("global_toc", global_toc);
60
             ("source_anchor", source_anchor);
61
             ("preamble", `String (json_of_html preamble));
8✔
62
             ("content", `String (json_of_html content));
8✔
63
           ]))
64
  in
65
  { Odoc_document.Renderer.filename; content; children }
66

67
let make_src ~config ~url ~breadcrumbs content =
68
  let filename = Link.Path.as_filename ~is_flat:(Config.flat config) url in
4✔
69
  let filename = Fpath.add_ext ".json" filename in
4✔
70
  let htmlpp = Html.pp_elt ~indent:(Config.indent config) () in
4✔
71
  let json_to_string json = Utils.Json.to_string json in
2✔
72
  let content ppf =
73
    Format.pp_print_string ppf
2✔
74
      (json_to_string
2✔
75
         (`Object
76
           [
77
             ("type", `String "source");
78
             ("breadcrumbs", json_of_breadcrumbs breadcrumbs);
2✔
79
             ( "content",
80
               `String
81
                 (String.concat ""
2✔
82
                    (List.map (Format.asprintf "%a" htmlpp) content)) );
2✔
83
           ]))
84
  in
85
  { Odoc_document.Renderer.filename; content; children = [] }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc