Module Odoc_extension_registrySource

Odoc 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.

Sourcemodule Comment = Odoc_model.Comment
Sourcemodule Location_ = Odoc_model.Location_
Sourcetype resource =
  1. | Js_url of string
  2. | Css_url of string
  3. | Js_inline of string
  4. | Css_inline of string

Resources that can be injected into the page (HTML only)

Sourcetype support_file = {
  1. filename : string;
    (*

    Relative path, e.g., "extensions/admonition.css"

    *)
  2. content : string;
    (*

    File content

    *)
}

Support files that extensions want to output

Sourcetype asset = {
  1. asset_filename : string;
    (*

    Filename for the asset, e.g., "diagram-1.png"

    *)
  2. asset_content : bytes;
    (*

    Binary content

    *)
}

Binary asset generated by an extension (e.g., rendered PNG)

Sourcetype option_doc = {
  1. opt_name : string;
    (*

    Option name, e.g., "width"

    *)
  2. opt_description : string;
    (*

    What the option does

    *)
  3. opt_default : string option;
    (*

    Default value if any

    *)
}

Documentation for an extension option

Sourcetype extension_info = {
  1. info_kind : [ `Tag | `Code_block ];
    (*

    Type of extension

    *)
  2. info_prefix : string;
    (*

    The prefix this extension handles

    *)
  3. info_description : string;
    (*

    Short description of what it does

    *)
  4. info_options : option_doc list;
    (*

    Supported options

    *)
  5. info_example : string option;
    (*

    Example usage

    *)
}

Documentation/metadata for an extension

Sourcetype 'block extension_result = {
  1. content : 'block;
  2. overrides : (string * string) list;
  3. resources : resource list;
  4. 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.

Sourcetype 'block handler = string -> Comment.nestable_block_element Location_.with_location list -> 'block extension_result option

Type 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.

Sourceval handlers : (string, Obj.t) Hashtbl.t

The registry stores handlers indexed by prefix

Sourceval prefixes : (string, unit) Hashtbl.t

Registered prefixes for listing

Sourceval support_files : (string, support_file) Hashtbl.t

Support files registered by extensions

Sourceval register_handler : prefix:string -> 'block handler -> unit
Sourceval register_support_file : prefix:string -> support_file -> unit
Sourceval find_handler : prefix:string -> 'block handler option
Sourceval list_prefixes : unit -> String.t list
Sourceval list_support_files : unit -> support_file list
Sourceval prefix_of_tag : string -> string

Extract the prefix from a tag name (part before the first dot)

Code Block Handlers

Similar to custom tag handlers, but for code blocks like {@dot[...]}. Handlers can transform code blocks based on language and metadata.

Sourcetype code_block_meta = {
  1. language : string;
  2. tags : Odoc_parser.Ast.code_block_tag list;
}

Metadata for code blocks, extracted from parser AST

Sourcetype 'block code_block_handler = code_block_meta -> string -> 'block extension_result option

Type of code block handler functions. Takes metadata and code content, returns optional transformed result.

Sourceval code_block_handlers : (string, Obj.t) Hashtbl.t

Registry for code block handlers, indexed by language prefix

Sourceval code_block_prefixes : (string, unit) Hashtbl.t

Registered code block prefixes

Sourceval register_code_block_handler : prefix:string -> 'block code_block_handler -> unit
Sourceval find_code_block_handler : prefix:string -> 'block code_block_handler option
Sourceval list_code_block_prefixes : unit -> String.t list
Sourceval prefix_of_language : string -> string

Extract the prefix from a language tag (part before the first dot)

Extension Documentation

Extensions can register documentation that describes their options and usage. This is displayed by odoc extensions.

Sourceval extension_infos : (string, extension_info) Hashtbl.t

Registry for extension documentation

Sourceval register_extension_info : extension_info -> unit
Sourceval list_extension_infos : unit -> extension_info list