···11+(install
22+ (section doc)
33+ (files
44+ (parent_child_spec.mld as odoc-pages/deprecated/parent_child_spec.mld)
55+ (index.mld as odoc-pages/deprecated/index.mld))
66+ (package odoc))
+4
doc/deprecated/index.mld
···11+{0 Deprecated features}
22+33+Odoc 2.x had a different way to specify the hierarchy of the output pages. This still works,
44+though it is deprecated. Documentation for the feature may be found {{!page-parent_child_spec}here}.
+5-5
doc/driver.mld
···77For this reason, just like for building any multifiles OCaml project, [odoc]
88needs to be driven by a higher level tool. The driver will take care of calling
99the [odoc] command with the right arguments throughout the different
1010-phases. Several drivers for [odoc] exist, such as:
1111-{{:https://dune.readthedocs.io/en/stable/documentation.html}dune} and
1212-{{:https://erratique.ch/software/odig}odig}.
1010+phases. The {{!/odoc-driver/page-index}odoc-driver} package contains a "reference driver", that is kept up-to-date
1111+with the latest development of [odoc],
13121414-The [odoc] tool also contains a "reference driver", that is kept up-to-date
1515-with the latest development of [odoc].
1313+Several drivers for [odoc] exist, such as:
1414+{{:https://dune.readthedocs.io/en/stable/documentation.html}dune} and
1515+{{!/odig/page-index}odig}.
16161717This document explains how to drive [odoc], as of version 3. It is not needed to
1818know any of this to {e use} [odoc], it is targeted at driver authors, tools that
···24242525[odoc_driver] is actually three drivers:
26262727-1. [odoc_driver] - The standard driver.
2828-2. [odoc_driver_voodoo] - The driver adapted for producing the documentation used by ocaml.org.
2929-3. [odoc_driver_monorepo] - An experimental driver for producing documentation of a dune-managed monorepo.
2727+- [odoc_driver] - The standard driver.
2828+- [odoc_driver_voodoo] - The driver adapted for producing the documentation used by ocaml.org.
2929+- [odoc_driver_monorepo] - An experimental driver for producing documentation of a dune-managed monorepo.
30303131What follows applies mostly to the first of these.
3232
+1-2
doc/dune
···99 ocamldoc_differences
1010 odoc_for_authors
1111 cheatsheet
1212- json
1313- parent_child_spec))
1212+ json))
14131514; Uncomment to run mdx on the documentation's code blocks.
1615; (mdx
···11-@children_order dune odoc_for_authors cheatsheet features ocamldoc_differences interface parent_child_spec driver json
22-@short_title [odoc]
11+@children_order odoc_for_authors cheatsheet dune features ocamldoc_differences interface driver json deprecated/
22+@short_title The odoc documentation generator
3344{0 The [odoc] documentation generator}
55···4141- an {e expander}, which can expand complex module-type expressions while preserving their structure, including comment, includes, and
4242more. If you've ever wondered what values there are in your module [M : Base.Applicative.S with type t := u], [odoc] will show you!
43434444-{1 For Library Authors}
4444+{1 For Authors}
45454646-For guidance on how to document your OCaml project, see {{!page-odoc_for_authors}[odoc] for authors}.
4646+For guidance on how to document your OCaml project, see {!page-odoc_for_authors}.
47474848{1 For Integrators}
49495050To integrate [odoc] into your tool, webpage or any other
5151setting, you'll need to understand {{!page-driver}how to drive [odoc]}.
5252-5353-{1 Page Index}
5454-5555-The main other pages of this site:
5656-- {!page-odoc_for_authors} gives information for [odoc] authors.
5757-- {!page-cheatsheet} provides a quick quide for [odoc] markdown.
5858-- {!page-features} explores [odoc]'s language features.
5959-- {!page-driver} describes how [odoc] produces documentation.
6060-- {!page-ocamldoc_differences} outlines differences from OCamldoc.
6161-- {!page-dune} shows how to create docs using Dune.
6262-- {!page-parent_child_spec} delineates parent/child specifications.
6363-- {!page-interface} describes [odoc]'s public-facing interface and their support guarantees.
+112-51
doc/odoc_for_authors.mld
···1515'drivers' of [odoc] at time of writing, each with their own strengths and
1616weaknesses:
17171818+- {{!/odoc-driver/page-index}The reference driver} is the most up-to-date driver,
1919+ and incorporates all of the features of odoc. It is also used for the docs
2020+ published on ocaml.org. It does not feature fast rebuilds, nor keeping a
2121+ switch-wide cache of documentation. Install the package to document via
2222+ [opam] and run
2323+{v
2424+$ odoc_driver <pkg>
2525+v}
2626+ to build the docs. The output will appear in the directory `_html` by default.
1827- {{:https://dune.build/}Dune} is the best way to view docs while
1928 developing your project. We have a {{!page-dune}page} describing
2029 how to use it, but the short version is:
···2736{v
2837$ odig doc odig
2938v}
3030-- {{!page-driver}The reference driver} is the simplest driver, useful if you
3131- want to see how to integrate it with your own projects.
3232-- {{:https://github.com/ocaml-doc/voodoo}Voodoo} is the driver used to create
3333- the docs for {{:https://ocaml.org/packages}the OCaml website}.
3939+4040+{1:packagedocs Documenting a package}
4141+4242+Documentation in OCaml is grouped together by {i package}. Each package may contain
4343+a number of documentation pages, organised into a hierarchy, and if the
4444+package contains {i libraries}, their interfaces form the rest of the package documentation.
4545+The pages are written in a subset of the usual {{!page-ocamldoc_differences}odoc markup},
4646+and the libraries are documented via in-line special comments in the source.
4747+Conceptually, the docs for every library are {i contained within} the docs of its package.
4848+4949+{2 Quickstart}
5050+5151+When a package is built with [dune], the simplest way to include docs in your package is
5252+to create a [doc] dir, write [doc/index.mld] file containing the documentation for your
5353+package:
5454+5555+{v
5656+{0 My package documentation}
5757+5858+This is the documentation for my package!
5959+v}
6060+6161+then create the following [doc/dune] file:
6262+6363+{v
6464+(documentation)
6565+v}
6666+6767+More mld files can be added as necessary to the [doc] directory, and they will be included
6868+also.
6969+7070+This will work if you've only got one package defined in your dune project. If you've got
7171+more than one, you'll need to let dune know which package the docs are associated with:
7272+7373+{v
7474+(documentation
7575+ (package my_package))
7676+v}
7777+7878+Any assets you have will also need to be handled, and as this is a new feature in odoc 3,
7979+at time of writing dune does not have a convenient syntax for this. However, it still can
8080+be done, so if, for example, you have an image [asset.jpg] that you'd like to include in your
8181+doc, you can add the following to your [doc/dune] file:
8282+8383+{v
8484+(install
8585+ (section doc)
8686+ (files (asset.jpg as odoc-pages/asset.jpg)))
8787+v}
8888+8989+Odoc 3.0 introduces a per-package configuration file, {{!section-config-file}odoc-config.sexp}, which is important if you'd like your
9090+documentation to link to the docs of other packages or libraries. If your documentation needs
9191+this configuration file, this will also need to be installed as follows:
9292+9393+{v
9494+(install
9595+ (section doc)
9696+ (files odoc-config.sexp))
9797+v}
34983599{1:interfaces Documenting Your Interfaces}
361003737-[odoc] is built to produce documentation for your {e libraries}, and the unit of
3838-organisation is the {e module}. Documentation is written by putting
101101+As well as doc pages, [odoc] is built to produce documentation for your {e libraries},
102102+and the unit of organisation for these is the {e module}. Documentation is written by putting
39103{{!special_comments}special comments} into the source of the {e module interface} or,
40104less commonly, your {e module implementation}.
41105···399463- [odoc]: [ {!module-Foo.type-bar} ] - each element in the path may be prefixed by its type. This is
400464useful if there are ambiguous elements in any part of the path, e.g., in this case perhaps there is a
401465module type [Foo].
466466+- [odoc3]: [ {!/library_name/Module} ] - this is a path to them module [M] in library [library_name].
467467+This is useful if the module name is ambiguous, e.g., if there are two modules [M] in different libraries.
468468+You may need to add the library to the per-package config file.
469469+- [odoc3]: [ {!/package/path/to/page-foo} ] - this is a path to a page [foo] in the package [package].
470470+The package will need to be added to the per-package config file.
402471403472The prefixes supported are:
404473- [module]
···663732The light syntax has the advantages of being arguably more readable for small tables when viewing the source file directly. However, its content is restricted (for instance, no new line is allowed).
664733The heavy syntax is easier to write, can be more readable for big tables, and supports having any kind of content inside. It does not support alignment (yet).
665734666666-{2:media Medias}
735735+{2:media Media}
667736668668-Odoc 3.0 introduced new markup for medias. Medias are nestable blocks,
737737+Odoc 3.0 introduced new markup for media. Media are nestable blocks,
669738so they can be put inside lists and tables, but they cannot be
670739inlined, for instance in a link.
671740672672-There are currently three kinds of medias: image, audio, and
741741+There are currently three kinds of media: image, audio, and
673742video. Each of them can refer to the file either using an asset
674743reference, or a direct link.
675744···681750The markup for videos and audios is similar, replacing [image] by respectively
682751[video] and [audio].
683752684684-The replacement text is used for backends that do not support medias
753753+The replacement text is used for backends that do not support media
685754(latex and man), and for when a reference is unresolved. In the case
686755of an image, it is also used to generate an alternative text.
687756···878947complementary notes. An alternative would be to consider splitting into
879948multiple files.
880949881881-Finally, documentation pages should start with a level-0 heading, see
882882-{!section-"page-title"}. Level-0 headings should not be used elsewhere.
950950+Finally, documentation pages should start with a level-0 heading:
951951+952952+{v
953953+{0 Title of the page}
954954+v}.
955955+956956+Level-0 headings should not be used elsewhere.
883957884958The syntax for declaring sections is as follows:
885959···9321006See {!page-a.foo} for details
9331007v}
9341008935935-{1:doc-pages Writing Documentation Pages}
10091009+{1:config-file Configuration file}
9361010937937-Files with the [.mld] extension are called {e documentation pages} and should
938938-be used to complement API references with tutorials or guides. They are
939939-particularly suitable for OCaml and Reason because cross-references to
940940-definitions, both in the current package and for external packages, are
941941-supported.
10111011+[odoc] 3.0 introduced a per-package configuration file, [odoc-config.sexp]. This file is required if you
10121012+wish to make use of the cross-package linking feature, or sometimes if you wish to link to other libraries.
9421013943943-{2 Markup}
10141014+As an example, here is [odoc]'s configuration file:
9441015945945-The format of these [.mld] files is simply text that should be marked-up with
946946-the usual [odoc] markup as described on this page. A documentation page can be seen
947947-as a single regular docstring in a separate file.
10161016+{v
10171017+(libraries fmt)
10181018+(packages odoc-driver cmdliner odig)
10191019+v}
9481020949949-{2 Page Title}
10211021+This file applies to all pages and all modules of all libraries in a package. With this config file, the
10221022+modules of the [fmt] library, and the pages of the [odoc-driver], [cmdliner] and [odig] packages can be
10231023+linked to via the following syntax:
9501024951951-When defining a documentation page, make sure to supply a page title, as one is
952952-not generated by default (unlike for API reference documents where the module
953953-or module type name is used). The level-0 heading must be used for that
954954-purpose. For example:
10251025+{v
10261026+{!/fmt/module-Fmt}
10271027+{!/odoc-driver/page-index}
10281028+v}
9551029956956-{@text[
957957-{0 My page}
958958-...
959959-]}
960960-961961-Only one title is allowed per page. The following heading levels should be in
962962-the range from 1 to 5 (inclusive). Don't worry, [odoc] will generate a warning
963963-if you accidentally forget to include multiple titles.
964964-965965-{2 Usage}
966966-967967-The recommended way to setup documentation pages for your project is by using
968968-the Dune build system. It will automatically find and generate HTML for all
969969-[.mld] files in your project. See
970970-{{:https://dune.readthedocs.io/en/latest/documentation.html#documentation-stanza}
971971-Dune's configuration instructions} for more details.
972972-973973-{2 Referencing Pages}
974974-975975-Currently the generated HTML pages are not be automatically referenced in the
976976-index page. You must manually add links to point to the pages in your document.
10301030+Important note: In order for this to work on ocaml.org, it is necessary that the tool used to build the
10311031+docs is aware that extra packages are required. If the package is already a dependency, then nothing needs
10321032+to be done. If it can be added without introducing dependency cycles, it can be added to the normal
10331033+dependencies field. If it would otherwise introduce a cycle into the dependencies, then it must be added
10341034+to an extra field. In the case of odoc, because the docs of [odoc] wish to link to the docs of [odoc-driver],
10351035+but [odoc-driver] depends on odoc, the following must be added to the [odoc]'s opam file:
9771036978978-For example, if you have a page called [my_page.mld], you can create a
979979-link to it with [{{!page-my_page}My page}] in your [index.mld] or
980980-anywhere else in your documentation.
10371037+{v
10381038+x-extra-doc-deps: [
10391039+ "odoc-driver" {>= "3.0.0"}
10401040+]
10411041+v}
···30303131 let all = Packages.remap_virtual all in
32323333- Logs.debug (fun m -> m "all: %a" Fmt.Dump.(list Packages.pp) all);
3433 let partial =
3534 match all with
3635 | [ p ] ->