Skip to content

Commit 329a909

Browse files
committed
Compatibility with odoc.2.4.1
1 parent f7a7a09 commit 329a909

File tree

15 files changed

+127
-75
lines changed

15 files changed

+127
-75
lines changed

dune-project

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@
5151
"Voodoo is an odoc driver used to generate OCaml.org's package documentation. voodoo-do runs the compilation step.")
5252
(depends
5353
voodoo-lib
54-
; odoc.2.2.0 pinned by the pipeline
54+
; odoc.2.4.1 pinned by the pipeline
5555
(odoc
56-
(= 2.2.2))
57-
(odoc-parser
58-
(= 2.0.0))
56+
(>= 2.4.1))
5957
bos
6058
astring
6159
cmdliner
@@ -71,11 +69,9 @@
7169
(omd
7270
(= 2.0.0~alpha3))
7371
voodoo-lib
74-
; odoc.2.2.0 pinned by the pipeline
72+
; odoc.2.4.1 pinned by the pipeline
7573
(odoc
76-
(= 2.2.2))
77-
(odoc-parser
78-
(= 2.0.0))
74+
(>= 2.4.1))
7975
conf-pandoc
8076
astring
8177
cmdliner

src/voodoo-gen/generate_html_docs.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ let document_of_odocl ~syntax input =
1010
Ok (Renderer.document_of_page ~syntax odoctree)
1111
| Unit_content odoctree ->
1212
Ok (Renderer.document_of_compilation_unit ~syntax odoctree)
13+
| Source_tree_content _ ->
14+
Error (`Msg "document_of_odocl: Source_tree_content unexpected")
1315

1416
let render_document ~output odoctree =
1517
let aux pages =
@@ -69,24 +71,26 @@ let render ~output file =
6971
get_subpages subpage.content)
7072
|> List.flatten)
7173
in
72-
get_subpages document
74+
match document with
75+
| Odoc_document.Types.Document.Page p -> get_subpages p
76+
| _ -> []
7377
in
7478
Ok urls
7579

7680
let render_text ~id ~output doc =
7781
let url = Odoc_document.Url.Path.from_identifier id in
78-
Markdown.read_plain doc url >>= render_document ~output
82+
Markdown.read_plain doc url >>= fun p -> render_document ~output (Page p)
7983

8084
let render_markdown ~id ~output doc =
8185
let url = Odoc_document.Url.Path.from_identifier id in
8286
match Markdown.read_md doc url with
83-
| Ok page -> render_document ~output page
87+
| Ok page -> render_document ~output (Page page)
8488
| Error _ -> render_text ~id ~output doc
8589

8690
let render_org ~id ~output doc =
8791
let url = Odoc_document.Url.Path.from_identifier id in
8892
match Markdown.read_org doc url with
89-
| Ok page -> render_document ~output page
93+
| Ok page -> render_document ~output (Page page)
9094
| Error _ -> render_text ~id ~output doc
9195

9296
let render_other ~output ~parent ~otherdocs =

src/voodoo-gen/markdown.ml

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ let rec block : 'attr block -> intermediate = function
4242
| Blockquote (_, _bs) -> Bl []
4343
| Thematic_break _ -> Bl []
4444
| Heading (_, n, i) ->
45-
It (Heading { label = None; level = n; title = inline i })
45+
It
46+
(Heading
47+
{ label = None; level = n; title = inline i; source_anchor = None })
4648
| Code_block (_, _a, b) ->
4749
Bl
4850
[
@@ -69,26 +71,28 @@ let of_content content ~name ~url =
6971
let md = Omd.of_string content in
7072
let intermediate = blocks md in
7173
let items = List.map (function It x -> x | Bl x -> Text x) intermediate in
74+
let open Odoc_document.Types.Page in
7275
Ok
7376
(match items with
74-
| [] -> Odoc_document.Types.Page.{ preamble = []; items = []; url }
77+
| [] -> { preamble = []; items = []; url; source_anchor = None }
7578
| (Heading _ as x) :: rest ->
76-
Odoc_document.Types.Page.{ preamble = [ x ]; items = rest; url }
79+
{ preamble = [ x ]; items = rest; url; source_anchor = None }
7780
| _ ->
78-
Odoc_document.Types.Page.
79-
{
80-
preamble =
81-
[
82-
Heading
83-
{
84-
label = None;
85-
level = 1;
86-
title = [ { desc = Text name; attr = [] } ];
87-
};
88-
];
89-
items;
90-
url;
91-
})
81+
{
82+
preamble =
83+
[
84+
Heading
85+
{
86+
label = None;
87+
level = 1;
88+
title = [ { desc = Text name; attr = [] } ];
89+
source_anchor = None;
90+
};
91+
];
92+
items;
93+
url;
94+
source_anchor = None;
95+
})
9296

9397
let read_org f url =
9498
let name = Fpath.basename f in
@@ -108,18 +112,20 @@ let read_md f url =
108112
let read_plain f url =
109113
let name = Fpath.basename f in
110114
Bos.OS.File.read f >>= fun content ->
115+
let open Odoc_document.Types.Page in
111116
Ok
112-
Odoc_document.Types.Page.
113-
{
114-
url;
115-
items = [ Text [ { desc = Verbatim content; attr = [] } ] ];
116-
preamble =
117-
[
118-
Heading
119-
{
120-
label = None;
121-
level = 1;
122-
title = [ { desc = Text name; attr = [] } ];
123-
};
124-
];
125-
}
117+
{
118+
url;
119+
items = [ Text [ { desc = Verbatim content; attr = [] } ] ];
120+
preamble =
121+
[
122+
Heading
123+
{
124+
label = None;
125+
level = 1;
126+
title = [ { desc = Text name; attr = [] } ];
127+
source_anchor = None;
128+
};
129+
];
130+
source_anchor = None;
131+
}

src/voodoo-gen/search_index.ml

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,65 @@ type entry = {
99
module Generate = struct
1010
(** Get plain text doc-comment from a doc comment *)
1111

12+
module C = Odoc_model.Comment
13+
1214
let get_value x = x.Odoc_model.Location_.value
1315

14-
let rec string_of_doc (doc : Odoc_model.Comment.docs) =
16+
let rec string_of_doc (doc : C.docs) =
1517
doc |> List.map get_value
1618
|> List.map s_of_block_element
1719
|> String.concat " "
1820

19-
and s_of_block_element (be : Odoc_model.Comment.block_element) =
21+
and s_of_block_element (be : C.block_element) =
2022
match be with
2123
| `Paragraph is -> inlines is
2224
| `Tag _ -> ""
2325
| `List (_, ls) ->
2426
List.map (fun x -> x |> List.map get_value |> List.map nestable) ls
2527
|> List.concat |> String.concat " "
26-
| `Heading (_, _, h) -> link_content h
28+
| `Heading (_, _, h) -> inlines h
2729
| `Modules _ -> ""
28-
| `Code_block (_, s) -> s |> get_value
30+
| `Code_block (_, s, _) -> s |> get_value
2931
| `Verbatim v -> v
3032
| `Math_block m -> m
33+
| `Table { data; _ } -> grid data
34+
35+
and cell (c : _ C.cell) =
36+
c |> fst |> List.map (fun x -> get_value x |> nestable) |> String.concat " "
3137

32-
and nestable (n : Odoc_model.Comment.nestable_block_element) =
33-
s_of_block_element (n :> Odoc_model.Comment.block_element)
38+
and row (r : _ C.row) = r |> List.map cell |> String.concat " "
39+
and grid (g : _ C.grid) = g |> List.map row |> String.concat " "
3440

35-
and inlines is =
36-
is |> List.map get_value |> List.map inline |> String.concat ""
41+
and nestable (n : C.nestable_block_element) =
42+
s_of_block_element (n :> C.block_element)
3743

38-
and inline (i : Odoc_model.Comment.inline_element) =
44+
and inlines (is : C.inline_element C.with_location list) =
45+
is |> List.map (fun x -> get_value x |> inline) |> String.concat ""
46+
47+
and leaf_inline (i : C.leaf_inline_element) =
3948
match i with
40-
| `Code_span s -> s
49+
| `Space -> " "
4150
| `Word w -> w
51+
| `Code_span s -> s
4252
| `Math_span m -> m
43-
| `Space -> " "
53+
| `Raw_markup (_, _) -> ""
54+
55+
and inline (i : C.inline_element) =
56+
match i with
57+
| #C.leaf_inline_element as i -> leaf_inline (i :> C.leaf_inline_element)
58+
| `Styled (_, b) -> inlines b
4459
| `Reference (_, c) -> link_content c
4560
| `Link (_, c) -> link_content c
46-
| `Styled (_, b) -> inlines b
47-
| `Raw_markup (_, _) -> ""
4861

49-
and link_content l =
50-
l |> List.map get_value
51-
|> List.map non_link_inline_element
52-
|> String.concat ""
62+
and link_content (l : C.link_content) = non_link_inlines l
63+
64+
and non_link_inline (x : C.non_link_inline_element) =
65+
match x with
66+
| #C.leaf_inline_element as x -> leaf_inline (x :> C.leaf_inline_element)
67+
| `Styled (_, b) -> non_link_inlines b
5368

54-
and non_link_inline_element (n : Odoc_model.Comment.non_link_inline_element) =
55-
inline (n :> Odoc_model.Comment.inline_element)
69+
and non_link_inlines (is : C.non_link_inline_element C.with_location list) =
70+
is |> List.map (fun x -> get_value x |> non_link_inline) |> String.concat ""
5671

5772
let rec full_name_aux : Odoc_model.Paths.Identifier.t -> string list =
5873
let open Odoc_model.Names in
@@ -80,6 +95,8 @@ module Generate = struct
8095
FieldName.to_string name :: full_name_aux (parent :> Identifier.t)
8196
| `Extension (parent, name) ->
8297
ExtensionName.to_string name :: full_name_aux (parent :> Identifier.t)
98+
| `ExtensionDecl (parent, _, name) ->
99+
ExtensionName.to_string name :: full_name_aux (parent :> Identifier.t)
83100
| `Exception (parent, name) ->
84101
ExceptionName.to_string name :: full_name_aux (parent :> Identifier.t)
85102
| `CoreException name -> [ ExceptionName.to_string name ]
@@ -96,6 +113,17 @@ module Generate = struct
96113
:: full_name_aux (parent :> Identifier.t)
97114
| `Label (parent, name) ->
98115
LabelName.to_string name :: full_name_aux (parent :> Identifier.t)
116+
| `SourceDir (parent, name) ->
117+
name :: full_name_aux (parent :> Identifier.t)
118+
| `AssetFile (parent, name) ->
119+
name :: full_name_aux (parent :> Identifier.t)
120+
| `SourceLocationMod parent -> full_name_aux (parent :> Identifier.t)
121+
| `SourceLocation (parent, name) ->
122+
DefName.to_string name :: full_name_aux (parent :> Identifier.t)
123+
| `SourceLocationInternal (parent, name) ->
124+
LocalName.to_string name :: full_name_aux (parent :> Identifier.t)
125+
| `SourcePage (parent, name) ->
126+
name :: full_name_aux (parent :> Identifier.t)
99127

100128
let prefixname :
101129
[< Odoc_model.Paths.Identifier.t_pv ] Odoc_model.Paths.Identifier.id ->
@@ -134,7 +162,14 @@ module Generate = struct
134162
| `CoreException _ -> "core exception"
135163
| `Constructor _ -> "constructor"
136164
| `Extension _ -> "extension"
165+
| `ExtensionDecl _ -> "extension-decl"
137166
| `Root _ -> "root"
167+
| `SourceDir _ -> "source dir"
168+
| `AssetFile _ -> "asset file"
169+
| `SourceLocationMod _ -> "source location mod"
170+
| `SourceLocation _ -> "source location"
171+
| `SourceLocationInternal _ -> "source location internal"
172+
| `SourcePage _ -> "source page"
138173
in
139174
let url = Odoc_html.Link.href ~config ~resolve:(Base "") url in
140175
let json =
@@ -172,6 +207,7 @@ module Load_doc = struct
172207
| `Constructor (parent, _) -> is_internal (parent :> Identifier.t)
173208
| `Field (parent, _) -> is_internal (parent :> Identifier.t)
174209
| `Extension (parent, _) -> is_internal (parent :> Identifier.t)
210+
| `ExtensionDecl (parent, _, _) -> is_internal (parent :> Identifier.t)
175211
| `Exception (parent, _) -> is_internal (parent :> Identifier.t)
176212
| `CoreException _ -> false
177213
| `Value (_, name) -> ValueName.is_internal name
@@ -180,6 +216,13 @@ module Load_doc = struct
180216
| `Method (parent, _) -> is_internal (parent :> Identifier.t)
181217
| `InstanceVariable (parent, _) -> is_internal (parent :> Identifier.t)
182218
| `Label (parent, _) -> is_internal (parent :> Identifier.t)
219+
| `SourceDir (parent, _) -> is_internal (parent :> Identifier.t)
220+
| `AssetFile (parent, _) -> is_internal (parent :> Identifier.t)
221+
| `SourceLocationMod parent -> is_internal (parent :> Identifier.t)
222+
| `SourceLocation (parent, _) -> is_internal (parent :> Identifier.t)
223+
| `SourceLocationInternal (parent, _) ->
224+
is_internal (parent :> Identifier.t)
225+
| `SourcePage (parent, _) -> is_internal (parent :> Identifier.t)
183226

184227
let add t ppf =
185228
if is_internal t.id then ()

src/voodoo/mld.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let rec pp fmt v =
1111
let child_pp fmt = function
1212
| Odoc.CModule m -> Format.fprintf fmt "CModule %s" m
1313
| CPage p -> Format.fprintf fmt "CPage %s" p
14+
| CSrc p -> Format.fprintf fmt "CSrc %s" p
1415
in
1516
Format.fprintf fmt "{ path: %a; name: %s; parent: %a; children: %a }" Fpath.pp
1617
v.path v.name (Fmt.option pp) v.parent

src/voodoo/odoc.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let compile_deps file =
5050
Format.eprintf "Failed to find digest for self (%s)\n%!" name;
5151
None
5252

53-
type child = CModule of string | CPage of string
53+
type child = CModule of string | CPage of string | CSrc of string
5454

5555
let compile ?parent ?output path ~includes ~children =
5656
let cmd = Bos.Cmd.(v "odoc" % "compile" % Fpath.to_string path) in
@@ -61,7 +61,7 @@ let compile ?parent ?output path ~includes ~children =
6161
in
6262
let cmd =
6363
match parent with
64-
| Some str -> Bos.Cmd.(cmd % "--parent" % Printf.sprintf "\"%s\"" str)
64+
| Some str -> Bos.Cmd.(cmd % "--parent" % Printf.sprintf "page-\"%s\"" str)
6565
| None -> cmd
6666
in
6767
let cmd =
@@ -76,6 +76,7 @@ let compile ?parent ?output path ~includes ~children =
7676
match c with
7777
| CModule m -> "module-" ^ m
7878
| CPage p -> "page-\"" ^ p ^ "\""
79+
| CSrc p -> "src-" ^ p
7980
in
8081
Bos.Cmd.(cmd % "--child" % arg))
8182
cmd children

src/voodoo/odoc.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ val compile_deps : Fpath.t -> (string * string * compile_dep list) option
1616
type child =
1717
| CModule of string (** module name, e.g. 'String' *)
1818
| CPage of string (** page name, e.g. 'packages' *)
19+
| CSrc of string (* 'src' *)
1920

2021
val compile :
2122
?parent:string ->

src/voodoo/serialize/package_info.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Kind = struct
33
[ `Module
44
| `Page
55
| `LeafPage
6+
| `SourcePage
67
| `ModuleType
78
| `Parameter of int
89
| `Class
@@ -13,6 +14,7 @@ module Kind = struct
1314
| `Page -> "page"
1415
| `Module -> "module"
1516
| `LeafPage -> "leaf-page"
17+
| `SourcePage -> "source"
1618
| `ModuleType -> "module-type"
1719
| `Parameter arg_num -> Printf.sprintf "argument-%d" arg_num
1820
| `Class -> "class"
@@ -23,6 +25,7 @@ module Kind = struct
2325
| "page" -> `Page
2426
| "module" -> `Module
2527
| "leaf-page" -> `LeafPage
28+
| "source" -> `SourcePage
2629
| "module-type" -> `ModuleType
2730
| "class" -> `Class
2831
| "class-type" -> `ClassType

src/voodoo/serialize/package_info.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Kind : sig
33
[ `Module
44
| `Page
55
| `LeafPage
6+
| `SourcePage
67
| `ModuleType
78
| `Parameter of int
89
| `Class

test/can-render-org-files.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Converted the README.org file in HTML
3737
Content of automatically generated Index.mld is fine
3838
$ cat output/p/$PKG/1.0/doc/index.html.json | jq .
3939
{
40+
"type": "documentation",
4041
"uses_katex": false,
4142
"breadcrumbs": [
4243
{
@@ -61,6 +62,7 @@ Content of automatically generated Index.mld is fine
6162
}
6263
],
6364
"toc": [],
65+
"source_anchor": null,
6466
"preamble": "<h1 id=\"can-render-org-files-1.0\"><a href=\"#can-render-org-files-1.0\" class=\"anchor\"></a>can-render-org-files 1.0</h1>",
6567
"content": ""
6668
}

0 commit comments

Comments
 (0)