Odoc_extension_apiSourceOdoc Extension API
This module provides the interface for odoc tag extensions. Extensions are dynamically loaded plugins that handle custom tags like @note, @rfc, @example, etc.
These are the odoc types that extensions need to work with.
Resources that can be injected into the page (HTML only)
type asset = Odoc_extension_registry.asset = {asset_filename : string;Filename for the asset, e.g., "diagram-1.png"
*)asset_content : bytes;Binary content
*)}Binary asset generated by an extension. Assets are written alongside the HTML output. To reference an asset in your content, use the placeholder __ODOC_ASSET__filename__ which will be replaced with the correct relative path during HTML generation.
Extensions can register documentation describing their options and usage. This information is displayed by odoc extensions --help.
type option_doc = Odoc_extension_registry.option_doc = {opt_name : string;Option name, e.g., "width"
*)opt_description : string;What the option does
*)opt_default : string option;Default value if any
*)}Documentation for a single option
type extension_info = Odoc_extension_registry.extension_info = {info_kind : [ `Tag | `Code_block ];Type of extension
*)info_prefix : string;The prefix this extension handles
*)info_description : string;Short description
*)info_options : option_doc list;Supported options
*)info_example : string option;Example usage
*)}Documentation/metadata for an extension
type extension_output = {content : Block.t;Universal content - used by all backends unless overridden
*)overrides : (string * string) list;Backend-specific raw content overrides. E.g., ("html", "<div>...</div>"); ("markdown", "...")
resources : resource list;Page-level resources (JS/CSS). Only used by HTML backend.
*)assets : asset list;Binary assets to write alongside HTML output. Reference in content using __ODOC_ASSET__filename__ placeholder.
}Output from the document phase
Raised when an extension receives a tag variant it doesn't support
Extensions can also handle code blocks like {@dot[...]} or {@mermaid[...]}. These extensions receive the language tag, metadata (key=value pairs), and the code content.
Metadata for code blocks
The signature that code block extensions must implement
Extensions can register support files (CSS, JS, images, etc.) that will be output by odoc support-files.
type support_file = Odoc_extension_registry.support_file = {filename : string;Relative path, e.g., "extensions/admonition.css"
*)content : string;File content
*)}Extensions register themselves here when loaded. odoc queries the registry when processing custom tags.
Extract plain text from nestable block elements (for simple parsing)
val text_of_nestable_block_elements :
Comment.nestable_block_element Location_.with_location list ->
stringCreate an inline link
Create an empty extension output with just content
val get_binding :
'a ->
[< `Binding of
'a Odoc_parser.Loc.with_location * 'b Odoc_parser.Loc.with_location
| `Tag of 'c ]
list ->
'b optionGet the value of a binding from code block tags. E.g., for {@dot width=500[...]}, get_binding "width" meta.tags returns Some "500".
val has_tag :
'a ->
[< `Binding of 'b | `Tag of 'a Odoc_parser.Loc.with_location ] list ->
boolCheck if a bare tag is present in code block tags. E.g., for {@ocaml line-numbers[...]}, has_tag "line-numbers" meta.tags returns true.
val get_all_bindings :
[< `Binding of
'a Odoc_parser.Loc.with_location * 'b Odoc_parser.Loc.with_location
| `Tag of 'c ]
list ->
('a * 'b) listGet all bindings as a list of (key, value) pairs
val get_all_tags :
[< `Binding of 'a | `Tag of 'b Odoc_parser.Loc.with_location ] list ->
'b listGet all bare tags as a list of names