Skip to content

Commit d373214

Browse files
committed
Allow html-generate remap config to be specified in a file
1 parent dd665da commit d373214

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/odoc/bin/main.ml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,31 @@ module Odoc_html_args = struct
11511151
let doc = "Remap an identifier to an external URL." in
11521152
Arg.(value & opt_all convert_remap [] & info [ "R" ] ~doc)
11531153

1154+
let remap_file =
1155+
let doc = "File containing remap rules." in
1156+
Arg.(value & opt (some file) None & info ~docv:"FILE" ~doc [ "remap-file" ])
1157+
11541158
let extra_args =
11551159
let config semantic_uris closed_details indent theme_uri support_uri
1156-
search_uris flat as_json remap =
1160+
search_uris flat as_json remap remap_file =
11571161
let open_details = not closed_details in
1162+
let remap =
1163+
match remap_file with
1164+
| None -> remap
1165+
| Some f ->
1166+
let ic = open_in f in
1167+
let rec loop acc =
1168+
match input_line ic with
1169+
| exception _ ->
1170+
close_in ic;
1171+
acc
1172+
| line -> (
1173+
match Astring.String.cut ~sep:":" line with
1174+
| Some (orig, mapped) -> loop ((orig, mapped) :: acc)
1175+
| None -> loop acc)
1176+
in
1177+
loop []
1178+
in
11581179
let html_config =
11591180
Odoc_html.Config.v ~theme_uri ~support_uri ~search_uris ~semantic_uris
11601181
~indent ~flat ~open_details ~as_json ~remap ()
@@ -1163,7 +1184,7 @@ module Odoc_html_args = struct
11631184
in
11641185
Term.(
11651186
const config $ semantic_uris $ closed_details $ indent $ theme_uri
1166-
$ support_uri $ search_uri $ flat $ as_json $ remap)
1187+
$ support_uri $ search_uri $ flat $ as_json $ remap $ remap_file)
11671188
end
11681189

11691190
module Odoc_html = Make_renderer (Odoc_html_args)

test/integration/remap.t/remap.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prefix/otherpkg/:https://mysite.org/bar/
2+
prefix/:https://mysite.org/foo/
3+

test/integration/remap.t/run.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ The order shouldn't matter, the longest prefix ought to win
2525
$ grep Otherlib/index.html _html3/prefix/mypkg/Test/index.html _html4/prefix/mypkg/Test/index.html
2626
_html3/prefix/mypkg/Test/index.html: <a href="https://mysite.org/bar/Otherlib/index.html#type-t">Otherlib.t
2727
_html4/prefix/mypkg/Test/index.html: <a href="https://mysite.org/bar/Otherlib/index.html#type-t">Otherlib.t
28+
29+
$ odoc html-generate -o _html5 --indent _odoc/prefix/mypkg/test.odocl --remap-file remap.txt
30+
$ grep Otherlib/index.html _html5/prefix/mypkg/Test/index.html
31+
<a href="https://mysite.org/bar/Otherlib/index.html#type-t">Otherlib.t
32+
33+

0 commit comments

Comments
 (0)