Architecture
Tealdoc features a flexible, input-language-agnostic architecture.
- Registry: The central piece is the
registry, which stores all discovered documentationitems. - Item: An
itemis a piece of data in the registry representing a code entity (like a function or record) or an abstract concept. Each item has a unique path and can contain child items. - Parser: The input layer that processes source files and populates the registry with items.
- Consumers: Built-in consumers (like the Markdown generator) that process the registry to create output.
This design allows you to extend Tealdoc with custom tags, parsers for other languages, or new output generators.
Using Tealdoc Programmatically
You can use the Tealdoc API to process files and access the registry directly.
local tealdoc = require("tealdoc")
local DefaultEnv = require("tealdoc.default_env")
-- Create a default environment, which registers all built-in
-- parsers, tags, and generator phases.
local env = DefaultEnv.create()
-- You can configure the environment programmatically
-- env.include_all = true
tealdoc.process_file("hello.tl", env)
for path, item in env.registry:each() do
print(path, item.name)
end
Adding Custom Tags
You can extend Tealdoc with your own tags by creating a custom tag handler.
local my_tag_handler: tealdoc.TagHandler = {
name = "my_tag",
with_param = true,
with_description = true,
handle = function(ctx: tealdoc.TagHandler.Context)
-- `ctx` contains the item, param, description, etc.
print("Parameter:", ctx.param)
print("Description:", ctx.description)
ctx.item.attributes["my_attribute"] = "hello world!"
end,
}
-- Then register it with the environment:
-- env.tag_handlers:add(my_tag_handler)
Plugins
You can easily extend Tealdoc with plugins. A plugin is a Lua module that implements the tealdoc.Plugin interface. These can be loaded via the command line, using the --plugin option, or programmatically.
local MyPlugin: tealdoc.Plugin = {
name = "my_plugin",
run = function(env: tealdoc.Env)
--- This function is called when the plugin is loaded.
--- You can access the environment and modify it.
--- For example, you can add custom tags or parsers.
end,
}
--- Note that the plugins loaded via the command line must behave like Lua modules.
return MyPlugin