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

ocaml / odoc / 1820

17 Jan 2024 01:21PM CUT coverage: 56.493% (+0.01%) from 56.482%
1820

push

github

panglesd
When generating a hidden module, mention why it is empty.

Signed-off-by: Paul-Elliot <peada@free.fr>

7104 of 12575 relevant lines covered (56.49%)

819.95 hits per line

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

0.0
/src/html/html_source.ml
1
open Odoc_document.Types
2
open Tyxml
3

4
let html_of_doc ~config ~resolve docs =
5
  let open Html in
×
6
  let a :
7
      ( [< Html_types.a_attrib ],
8
        [< Html_types.span_content_fun ],
9
        [> Html_types.span ] )
10
      star =
11
    Unsafe.node "a"
×
12
    (* Makes it possible to use <a> inside span. Although this is not standard (see
13
        https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories)
14
        it is validated by the {{:https://validator.w3.org/nu/#textarea}W3C}. *)
15
  in
16
  (* [a] tags should not contain in other [a] tags. If this happens, browsers
17
     start to be really weird. If PPX do bad things, such a situation could
18
     happen. We manually avoid this situation. *)
19
  let rec doc_to_html ~is_in_a doc =
20
    match doc with
×
21
    | Source_page.Plain_code s -> [ txt s ]
×
22
    | Tagged_code (info, docs) -> (
×
23
        let is_in_a = match info with Link _ -> true | _ -> is_in_a in
×
24
        let children = List.concat @@ List.map (doc_to_html ~is_in_a) docs in
×
25
        match info with
×
26
        | Syntax tok -> [ span ~a:[ a_class [ tok ] ] children ]
×
27
        | Link anchor ->
×
28
            let href = Link.href ~config ~resolve anchor in
29
            [ a ~a:[ a_href href ] children ]
×
30
        | Anchor lbl -> [ span ~a:[ a_id lbl ] children ])
×
31
  in
32
  span ~a:[] @@ List.concat @@ List.map (doc_to_html ~is_in_a:false) docs
×
33

34
let count_lines_in_string s =
35
  let n = ref 0 in
×
36
  String.iter (function '\n' -> incr n | _ -> ()) s;
×
37
  !n
×
38

39
(** Traverse the doc to count the number of lines. *)
40
let rec count_lines_in_span = function
41
  | Source_page.Plain_code s -> count_lines_in_string s
×
42
  | Tagged_code (_, docs) -> count_lines docs
×
43

44
and count_lines = function
45
  | [] -> 0
×
46
  | hd :: tl -> count_lines_in_span hd + count_lines tl
×
47

48
let rec line_numbers acc n =
49
  let open Html in
×
50
  if n < 1 then acc
×
51
  else
52
    let l = string_of_int n in
×
53
    let anchor =
×
54
      a
55
        ~a:[ a_id ("L" ^ l); a_class [ "source_line" ]; a_href ("#L" ^ l) ]
×
56
        [ txt l ]
×
57
    in
58
    line_numbers (anchor :: txt "\n" :: acc) (n - 1)
×
59

60
let html_of_doc ~config ~resolve docs =
61
  let open Html in
×
62
  pre
63
    ~a:[ a_class [ "source_container" ] ]
×
64
    [
65
      code
×
66
        ~a:[ a_class [ "source_line_column" ] ]
×
67
        (line_numbers [] (count_lines docs));
×
68
      code
×
69
        ~a:[ a_class [ "source_code" ] ]
×
70
        [ html_of_doc ~config ~resolve docs ];
×
71
    ]
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