Skip to content

Commit a372a7d

Browse files
committed
HTML renderer: option to omit breadcrumbs
1 parent c52ebb3 commit a372a7d

File tree

9 files changed

+72
-7
lines changed

9 files changed

+72
-7
lines changed

src/html/config.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ type t = {
77
indent : bool;
88
flat : bool;
99
open_details : bool;
10+
omit_breadcrumbs : bool;
1011
}
1112

12-
let v ?theme_uri ?support_uri ~semantic_uris ~indent ~flat ~open_details () =
13-
{ theme_uri; support_uri; semantic_uris; indent; flat; open_details }
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 }
1415

1516
let theme_uri config =
1617
match config.theme_uri with None -> Types.Relative None | Some uri -> uri
@@ -25,3 +26,5 @@ let indent config = config.indent
2526
let flat config = config.flat
2627

2728
let open_details config = config.open_details
29+
30+
let omit_breadcrumbs config = config.omit_breadcrumbs

src/html/config.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ val v :
99
indent:bool ->
1010
flat:bool ->
1111
open_details:bool ->
12+
omit_breadcrumbs:bool ->
1213
unit ->
1314
t
1415

@@ -23,3 +24,5 @@ val indent : t -> bool
2324
val flat : t -> bool
2425

2526
val open_details : t -> bool
27+
28+
val omit_breadcrumbs : t -> bool

src/html/tree.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let page_creator ~config ~url name header toc content =
7272
]
7373
in
7474

75-
let breadcrumbs =
75+
let gen_breadcrumbs () =
7676
let rec get_parents x =
7777
match x with
7878
| [] -> []
@@ -130,6 +130,7 @@ let page_creator ~config ~url name header toc content =
130130
make_navigation ~up_url l
131131
in
132132

133+
let breadcrumbs = if Config.omit_breadcrumbs config then [] else gen_breadcrumbs () in
133134
let body =
134135
breadcrumbs
135136
@ [ Html.header ~a:[ Html.a_class [ "odoc-preamble" ] ] header ]

src/odoc/bin/main.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,20 @@ module Odoc_html_args = struct
516516
in
517517
Arg.(value & flag & info ~docs ~doc [ "flat" ])
518518

519+
let omit_breadcrumbs =
520+
let doc =
521+
"Don't emit the breadcrumbs navigation element"
522+
in
523+
Arg.(value & flag & info ~docs ~doc [ "omit-breadcrumbs"])
519524
let extra_args =
520-
let config semantic_uris closed_details indent theme_uri support_uri flat =
525+
let config semantic_uris closed_details indent theme_uri support_uri flat omit_breadcrumbs =
521526
let open_details = not closed_details in
522527
Odoc_html.Config.v ~theme_uri ~support_uri ~semantic_uris ~indent ~flat
523-
~open_details ()
528+
~open_details ~omit_breadcrumbs ()
524529
in
525530
Term.(
526531
const config $ semantic_uris $ closed_details $ indent $ theme_uri
527-
$ support_uri $ flat)
532+
$ support_uri $ flat $ omit_breadcrumbs)
528533
end
529534

530535
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 ()
29+
~open_details:false ~omit_breadcrumbs: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/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
(libraries sexplib0 unix fpath)
2828
(enabled_if
2929
(>= %{ocaml_version} 4.04)))
30+
31+
(cram
32+
(deps %{bin:odoc}))
33+

test/generators/html_opts.t/run.t

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$ ocamlc -c -bin-annot test.mli
2+
$ ocamlc -c -bin-annot test2.mli
3+
$ odoc compile --package test test.cmti
4+
$ odoc compile --package test -I . test2.cmti
5+
$ odoc link test.odoc
6+
$ odoc link test2.odoc
7+
$ odoc html-generate test.odocl -o html --indent
8+
9+
This should have the breadcrumbs in it as a nav with id 'odoc-nav'. Let's also
10+
check it's got the expected content by looking for 'type-t'
11+
12+
$ grep odoc-nav html/test/Test/index.html
13+
<nav class="odoc-nav"><a href="../index.html">Up</a> –
14+
$ grep type-t html/test/Test/index.html
15+
<div class="spec type anchored" id="type-t">
16+
<a href="#type-t" class="anchor"></a>
17+
18+
Generate again, this time omitting the breadcrumbs:
19+
20+
$ odoc html-generate test.odocl -o html --omit-breadcrumbs --indent
21+
$ grep odoc-nav html/test/Test/index.html
22+
[1]
23+
$ grep type-t html/test/Test/index.html
24+
<div class="spec type anchored" id="type-t">
25+
<a href="#type-t" class="anchor"></a>
26+
27+
Check semantic_uris:
28+
$ odoc html-generate test2.odocl -o html --indent
29+
$ grep Test.t html/test/Test2/index.html
30+
<a href="../Test/index.html#type-t">Test.t</a>
31+
$ odoc html-generate test2.odocl -o html --semantic-uris --indent
32+
$ grep Test.t html/test/Test2/index.html
33+
<a href="../Test/#type-t">Test.t</a>
34+
35+
36+

test/generators/html_opts.t/test.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(** Test *)
2+
3+
(** {1 Section 1} *)
4+
5+
type t
6+
7+
(** {1 Section 2} *)
8+
9+
type u
10+

test/generators/html_opts.t/test2.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val v : Test.t
2+
3+

0 commit comments

Comments
 (0)