Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- New arguments to LaTeX generator, --shorten-beyond-depth and
--remove-functor-arg-link (@Octachron, #1337)
- New experimental markdown generator (@davesnx, #1341)
- `markdown-generate` command now accepts multiple `.odocl` files in a single
invocation, eliminating the need for shell scripting (@davesnx)

### Changed
- Remove cmdliner compatibility layer, no longer needed (@dbuenzli, #1328)
Expand Down
22 changes: 16 additions & 6 deletions src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ end = struct
let doc = "Input file." in
Arg.(required & pos 0 (some file) None & info ~doc ~docv:"FILE.odocl" [])

let input_odocl_list =
let doc = "Input file(s)." in
Arg.(non_empty & pos_all file [] & info ~doc ~docv:"FILE.odocl" [])

module Process = struct
let process extra _hidden directories output_dir syntax input_file
warnings_options =
Expand Down Expand Up @@ -902,11 +906,16 @@ end = struct
let process ~docs = Process.(cmd, info ~docs)

module Generate = struct
let generate extra _hidden output_dir syntax extra_suffix input_file
let generate extra _hidden output_dir syntax extra_suffix input_files
warnings_options sidebar =
let file = Fs.File.of_string input_file in
Rendering.generate_odoc ~renderer:R.renderer ~warnings_options ~syntax
~output:output_dir ~extra_suffix ~sidebar extra file
let process_file input_file =
let file = Fs.File.of_string input_file in
Rendering.generate_odoc ~renderer:R.renderer ~warnings_options ~syntax
~output:output_dir ~extra_suffix ~sidebar extra file
in
List.fold_left
~f:(fun acc input_file -> acc >>= fun () -> process_file input_file)
~init:(Ok ()) input_files

let sidebar =
let doc = "A .odoc-index file, used eg to generate the sidebar." in
Expand All @@ -927,11 +936,12 @@ end = struct
Term.(
const handle_error
$ (const generate $ R.extra_args $ hidden $ dst ~create:true () $ syntax
$ extra_suffix $ input_odocl $ warnings_options $ sidebar))
$ extra_suffix $ input_odocl_list $ warnings_options $ sidebar))

let info ~docs =
let doc =
Format.sprintf "Generate %s files from a $(i,.odocl)." R.renderer.name
Format.sprintf "Generate %s files from one or more $(i,.odocl) files."
R.renderer.name
in
Cmd.info ~docs ~doc (R.renderer.name ^ "-generate")
end
Expand Down
5 changes: 5 additions & 0 deletions test/integration/markdown-multi.t/a.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(** Module A *)

val x : int
(** A value *)

5 changes: 5 additions & 0 deletions test/integration/markdown-multi.t/b.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(** Module B *)

val y : string
(** B value *)

5 changes: 5 additions & 0 deletions test/integration/markdown-multi.t/c.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(** Module C *)

val z : bool
(** C value *)

22 changes: 22 additions & 0 deletions test/integration/markdown-multi.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Test markdown-generate with multiple .odocl files in a single invocation:

$ ocamlc -c -bin-annot a.mli
$ ocamlc -c -bin-annot b.mli
$ ocamlc -c -bin-annot c.mli
$ odoc compile --package test a.cmti
$ odoc compile --package test b.cmti
$ odoc compile --package test c.cmti
$ odoc link a.odoc
$ odoc link b.odoc
$ odoc link c.odoc

Generate with separate invocations:
$ odoc markdown-generate a.odocl -o markdown-separate
$ odoc markdown-generate b.odocl -o markdown-separate
$ odoc markdown-generate c.odocl -o markdown-separate

Generate with multiple files in one invocation:
$ odoc markdown-generate a.odocl b.odocl c.odocl -o markdown-multi

Verify both approaches produce identical output:
$ diff -r markdown-separate markdown-multi
Binary file added test/integration/markdown.t/list.cmi
Binary file not shown.
Binary file added test/integration/markdown.t/list.cmti
Binary file not shown.
Binary file added test/integration/markdown.t/test.cmi
Binary file not shown.
Binary file added test/integration/markdown.t/test.cmti
Binary file not shown.
Binary file added test/integration/markdown.t/test2.cmi
Binary file not shown.
Binary file added test/integration/markdown.t/test2.cmti
Binary file not shown.
2 changes: 1 addition & 1 deletion test/sources/source.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Html generation for implementation and mld/interface uses different commands
[2]
$ odoc html-generate --source a.ml --indent -o html impl-a.odocl
odoc: unknown option '--source'.
Usage: odoc html-generate [OPTION]… FILE.odocl
Usage: odoc html-generate [OPTION]… FILE.odocl
Try 'odoc html-generate --help' or 'odoc --help' for more information.
[2]

Expand Down