Odoc_extension_apiOdoc 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.
module Comment = Odoc_model.Commentmodule Location_ = Odoc_model.Location_module Block = Odoc_document.Types.Blockmodule Inline = Odoc_document.Types.Inlinemodule Description = Odoc_document.Types.Descriptionmodule Url = Odoc_document.Urlmodule Target = Odoc_document.Types.Targettype resource = Odoc_extension_registry.resource = 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
module type Extension = sig ... endThe signature that all tag extensions must implement
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
module type Code_Block_Extension = sig ... endThe 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.
module Registry : sig ... endval blocks_of_nestable_elements :
Odoc_document.Comment.Comment.nestable_block_element
Odoc_document.Comment.Comment.with_location
list ->
Odoc_document.Types.Block.one listConvert Comment AST to Block elements, preserving references and formatting. This is the proper way to convert tag content to renderable blocks.
val text_of_inline : Comment.inline_element Location_.with_location -> stringExtract plain text from nestable block elements (for simple parsing)
val text_of_inlines :
Comment.inline_element Location_.with_location list ->
stringval text_of_link_content : Comment.link_content -> stringval text_of_non_link :
Comment.non_link_inline_element Comment.with_location ->
stringval text_of_paragraph : Comment.paragraph -> stringval text_of_nestable_block_elements :
Comment.nestable_block_element Location_.with_location list ->
stringval paragraph : string -> Block.one listCreate a simple paragraph block
val link : url:string -> text:string -> Inline.one listCreate an inline link
val simple_output : Block.t -> extension_outputCreate 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