Odoc_extension_registryOdoc Extension Registry
This module provides a minimal registry for odoc tag extensions. It is kept separate to avoid circular dependencies between odoc_document and odoc_extension_api.
module Comment = Odoc_model.Commentmodule Location_ = Odoc_model.Location_Resources that can be injected into the page (HTML only)
type support_file = {filename : string;Relative path, e.g., "extensions/admonition.css"
*)content : string;File content
*)}Support files that extensions want to output
type asset = {asset_filename : string;Filename for the asset, e.g., "diagram-1.png"
*)asset_content : bytes;Binary content
*)}Binary asset generated by an extension (e.g., rendered PNG)
type 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 an extension option
type extension_info = {info_kind : [ `Tag | `Code_block ];Type of extension
*)info_prefix : string;The prefix this extension handles
*)info_description : string;Short description of what it does
*)info_options : option_doc list;Supported options
*)info_example : string option;Example usage
*)}Documentation/metadata for an extension
type 'block extension_result = {content : 'block;overrides : (string * string) list;resources : resource list;assets : asset list;Binary assets to write alongside the HTML output. Use __ODOC_ASSET__filename__ placeholder in content to reference.
}Result of processing a custom tag. We use a record with a polymorphic content type that gets instantiated with the actual Block.t by odoc_document.
type 'block handler =
string ->
Comment.nestable_block_element Location_.with_location list ->
'block extension_result optionType of handler functions stored in the registry. The handler takes a tag name and content, returns an optional result. If None, the tag is handled by the default mechanism.
val prefixes : (string, unit) Hashtbl.tRegistered prefixes for listing
val support_files : (string, support_file) Hashtbl.tSupport files registered by extensions
val register_handler : prefix:string -> 'block handler -> unitval register_support_file : prefix:string -> support_file -> unitval find_handler : prefix:string -> 'block handler optionval list_prefixes : unit -> String.t listval list_support_files : unit -> support_file listSimilar to custom tag handlers, but for code blocks like {@dot[...]}. Handlers can transform code blocks based on language and metadata.
type 'block code_block_handler =
code_block_meta ->
string ->
'block extension_result optionType of code block handler functions. Takes metadata and code content, returns optional transformed result.
Registry for code block handlers, indexed by language prefix
val code_block_prefixes : (string, unit) Hashtbl.tRegistered code block prefixes
val register_code_block_handler :
prefix:string ->
'block code_block_handler ->
unitval find_code_block_handler : prefix:string -> 'block code_block_handler optionval list_code_block_prefixes : unit -> String.t listExtract the prefix from a language tag (part before the first dot)
Extensions can register documentation that describes their options and usage. This is displayed by odoc extensions.
val extension_infos : (string, extension_info) Hashtbl.tRegistry for extension documentation
val register_extension_info : extension_info -> unitval list_extension_infos : unit -> extension_info list