Skip to content

Commit 182cc22

Browse files
committed
HTML renderer: option to omit the toc
1 parent a372a7d commit 182cc22

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

src/html/config.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ type t = {
88
flat : bool;
99
open_details : bool;
1010
omit_breadcrumbs : bool;
11+
omit_toc : bool;
1112
}
1213

13-
let v ?theme_uri ?support_uri ~semantic_uris ~indent ~flat ~open_details ~omit_breadcrumbs () =
14-
{ theme_uri; support_uri; semantic_uris; indent; flat; open_details; omit_breadcrumbs }
14+
let v ?theme_uri ?support_uri ~semantic_uris ~indent ~flat ~open_details ~omit_breadcrumbs ~omit_toc () =
15+
{ theme_uri; support_uri; semantic_uris; indent; flat; open_details; omit_breadcrumbs; omit_toc }
1516

1617
let theme_uri config =
1718
match config.theme_uri with None -> Types.Relative None | Some uri -> uri
@@ -27,4 +28,6 @@ let flat config = config.flat
2728

2829
let open_details config = config.open_details
2930

30-
let omit_breadcrumbs config = config.omit_breadcrumbs
31+
let omit_breadcrumbs config = config.omit_breadcrumbs
32+
33+
let omit_toc config = config.omit_toc

src/html/config.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ val v :
1010
flat:bool ->
1111
open_details:bool ->
1212
omit_breadcrumbs:bool ->
13+
omit_toc:bool ->
1314
unit ->
1415
t
1516

@@ -26,3 +27,5 @@ val flat : t -> bool
2627
val open_details : t -> bool
2728

2829
val omit_breadcrumbs : t -> bool
30+
31+
val omit_toc : t -> bool

src/html/tree.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ let page_creator ~config ~url name header toc content =
131131
in
132132

133133
let breadcrumbs = if Config.omit_breadcrumbs config then [] else gen_breadcrumbs () in
134+
let toc = if Config.omit_toc config then [] else html_of_toc toc in
134135
let body =
135136
breadcrumbs
136137
@ [ Html.header ~a:[ Html.a_class [ "odoc-preamble" ] ] header ]
137-
@ html_of_toc toc
138+
@ toc
138139
@ [ Html.div ~a:[ Html.a_class [ "odoc-content" ] ] content ]
139140
in
140141
Html.html head (Html.body ~a:[ Html.a_class [ "odoc" ] ] body)

src/odoc/bin/main.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,22 @@ module Odoc_html_args = struct
521521
"Don't emit the breadcrumbs navigation element"
522522
in
523523
Arg.(value & flag & info ~docs ~doc [ "omit-breadcrumbs"])
524+
525+
let omit_toc =
526+
let doc =
527+
"Don't emit the table of contents div"
528+
in
529+
Arg.(value & flag & info ~docs ~doc [ "omit-toc"])
530+
524531
let extra_args =
525-
let config semantic_uris closed_details indent theme_uri support_uri flat omit_breadcrumbs =
532+
let config semantic_uris closed_details indent theme_uri support_uri flat omit_breadcrumbs omit_toc =
526533
let open_details = not closed_details in
527534
Odoc_html.Config.v ~theme_uri ~support_uri ~semantic_uris ~indent ~flat
528-
~open_details ~omit_breadcrumbs ()
535+
~open_details ~omit_breadcrumbs ~omit_toc ()
529536
in
530537
Term.(
531538
const config $ semantic_uris $ closed_details $ indent $ theme_uri
532-
$ support_uri $ flat $ omit_breadcrumbs)
539+
$ support_uri $ flat $ omit_breadcrumbs $ omit_toc)
533540
end
534541

535542
module Odoc_html = Make_renderer (Odoc_html_args)

src/odoc/html_fragment.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let from_mld ~xref_base_uri ~resolver ~output ~warnings_options input =
2626
let page = Odoc_document.Comment.to_ir resolved.content in
2727
let config =
2828
Odoc_html.Config.v ~semantic_uris:false ~indent:false ~flat:false
29-
~open_details:false ~omit_breadcrumbs:false ()
29+
~open_details:false ~omit_breadcrumbs:false ~omit_toc:false ()
3030
in
3131
let html = Odoc_html.Generator.doc ~config ~xref_base_uri page in
3232
let oc = open_out (Fs.File.to_string output) in

test/generators/html_opts.t/run.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ Check semantic_uris:
3232
$ grep Test.t html/test/Test2/index.html
3333
<a href="../Test/#type-t">Test.t</a>
3434

35+
Check omission of toc:
36+
$ odoc html-generate test.odocl -o html --indent
37+
$ grep odoc-toc html/test/Test/index.html
38+
<nav class="odoc-toc">
39+
$ odoc html-generate test.odocl -o html --indent --omit-toc
40+
$ grep odoc-toc html/test/Test/index.html
41+
[1]
3542

3643

0 commit comments

Comments
 (0)