Skip to content
Directives Reference
On this page

Complete reference for all built-in selfdoc directives including code extraction, content blocks, and custom directive authoring.

#Directives Reference

selfdoc directives are inline blocks in Markdown templates that get resolved into content at build time. They pull live information from your source code, so documentation stays in sync with the implementation.

#Syntax

Directives use 6 marker types and come in two forms: self-closing one-liners for directives that need only attributes, and block directives for those that accept additional body content passed to the resolver function. The marker characters (:-:, :<:, :>:, :=:, :::, :@:) are designed to be visually distinctive in plain Markdown.

Note

Directives inside fenced code blocks (triple backticks) are ignored. You can safely show directive syntax in code examples without triggering resolution.

One-liner (self-closing, no body):

M markdown
:-: name key="value"

Block (with body content):

M markdown
:<: name key="value"
::: body line 1
::: body line 2
:>:

Block directives can also include additional attributes and a body separator:

M markdown
:<: name key="value"
:@: another="attr"
:=:
::: body content here
:>:

#Built-in Directives

The following table shows all built-in directives that selfdoc recognizes, their current implementation status (shipped or planned for a future release), and a brief description of what each directive extracts from source code or generates as content.

Built-in Directives
DirectiveDescription
callout-dangerStyled danger callout block
callout-importantStyled important callout block
callout-noteStyled note callout block
callout-tipStyled tip callout block
callout-warningStyled warning callout block
code-helpExtract CLI help/usage text and flag definitions
code-testEmbed test source code (whole file or specific function)
cvRender a curriculum vitae declared in a TOML document, plus the Person it states
list-crawlersList of the crawlers the generated robots.txt allows
list-glossaryDefinition list from Term: Definition lines
list-modulesList source modules with file paths and docstring summaries
list-treeFile/directory tree listing
prose-descExtract module/package docstring as prose text
refExtract module docstring, exported functions, and classes
table-commandsCLI command summary table from strictcli structure
table-configRender a config file (JSON/TOML) as a key-value table
table-config-schemaConfiguration field reference table from schema
table-depDependencies table from pyproject.toml
table-directivesTable of all core built-in directives
table-endpointREST API endpoint table from OpenAPI spec
table-lintsTable of every lint code selfdoc can emit, with its severity
table-schemaExtract dataclass/struct fields as a markdown table
varInterpolate project metadata value

#The exclude Attribute

The table-schema and table-config directives accept an optional exclude attribute — a comma-separated list of top-level keys to omit from the rendered table. Whitespace around commas is stripped. This is useful when a config or schema file contains keys that are too large, irrelevant, or internal to display in documentation, letting you render a focused subset of the file's structure.

M markdown
:-: table-config path="selfdoc.json" exclude="versions, locales"
:-: table-schema path="schema.json" exclude="internal_field"

If any excluded key does not exist in the file, a hard error is produced (no silent skips). Works with JSON, TOML, and JSONC files. For table-schema, exclude only applies when the path points to a data file — it has no effect when extracting from a source declaration such as a Go struct or a Python dataclass.

#Custom Directives

You can extend selfdoc with project-specific custom directives by registering them in your selfdoc.json configuration file, pointing each directive name to a script that implements the resolution logic. A .py script is loaded and called by an embedded Python driver under python3; any other script is executed directly with the same JSON payload on standard input.

{} json
{
  "directives": {
    "my-directive": "scripts/my-directive.py"
  }
}

A Python script must define a resolve(attrs, config, body) function that returns a Markdown string:

python
def resolve(attrs, config, body):
    """Called when :-: my-directive is encountered."""
    return "Generated content here"
  • attrs — dict of key-value pairs from the directive line
  • config — the full selfdoc.json configuration dict
  • body — list of body lines (empty list for one-liners); always a list, never None

Dispatch order is content directives, then custom directives, then the language extractors. A custom name therefore overrides a code-extraction directive such as ref, but not a content directive such as callout-note. A script that cannot be loaded, has no callable resolve, raises, or exits non-zero is a hard error that stops the build.

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • claudewheel A TUI Claude Code Launcher that lets you have more than one profile, manage sessions lifecycle, pick the exact CC version, model to use (even older unlisted ones), pick which GitHub account to use, etc.
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • fastware A batteries-included ASGI framework: msgspec JSON, a managed Granian server, dependency injection, SSE, WebSockets, auth, and a test client
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • safegit git wrapper CLI that gives each commit its own temporary index and retries ref updates on conflict, so concurrent agents share one repository
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
  • wesktop A Python framework that turns an ASGI web app into a desktop application, serving it from a local Granian server and displaying it in a native OS window via pywebview
Search