selfdoc v0.15.1 /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.

#Code Extraction

Code Extraction
DirectiveDescriptionRequiredOptional
code-helpExtract CLI help/usage text and flag definitionspath
code-testEmbed test source code (whole file or specific function)pathtarget
prose-descExtract module/package docstring as prose textpath
refExtract module docstring, exported functions, and classespathtarget
table-configRender a config file (JSON/TOML) as a key-value tablepathexclude
table-schemaExtract dataclass/struct fields as a markdown tablepathtarget, exclude

#Code Extraction Examples

**code-help**:

M markdown
:::code-help path="cli.py"

**code-test**:

M markdown
:::code-test path="tests/test_auth.py" target="test_login"

**prose-desc**:

M markdown
:::prose-desc path="mymodule"

**ref**:

M markdown
:::ref path="mymodule"

**table-config**:

M markdown
:::table-config path="config.json"

**table-schema**:

M markdown
:::table-schema path="models.py" target="User"

#Content Blocks

Content Blocks
DirectiveDescriptionRequiredOptional
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
list-featuresModule summaries from docstring first linespath
list-glossaryDefinition list from Term: Definition lines
list-modulesList source modules with file paths and docstring summariespath
list-treeFile/directory tree listingpathdepth
table-commandsCLI command summary table from strictcli structurepath
table-config-schemaConfiguration field reference table from schema
table-depDependencies table from pyproject.tomlpath
table-directivesTable of all core built-in directives
table-endpointREST API endpoint table from OpenAPI specpathendpoint, method
varInterpolate project metadata valuekey

#Content Blocks Examples

**callout-danger**:

M markdown
:::callout-danger
Dangerous operation.
:::

**callout-important**:

M markdown
:::callout-important
Do not skip this step.
:::

**callout-note**:

M markdown
:::callout-note
This is a note.
:::

**callout-tip**:

M markdown
:::callout-tip
Helpful hint here.
:::

**callout-warning**:

M markdown
:::callout-warning
Proceed with caution.
:::

**list-features**:

M markdown
:::list-features path="src/"

**list-glossary**:

M markdown
:::list-glossary
**API**: Application Programming Interface
:::

**list-modules**:

M markdown
:-: list-modules path="selfdoc/"

**list-tree**:

M markdown
:::list-tree path="src/"

**table-commands**:

M markdown
:-: table-commands path="selfdoc/"

**table-config-schema**:

M markdown
:-: table-config-schema

**table-dep**:

M markdown
:::table-dep path="pyproject.toml"

**table-directives**:

M markdown
:-: table-directives

**table-endpoint**:

M markdown
:-: table-endpoint path="openapi.json"

**var**:

M markdown
:-: var key="project.name"

#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 Python dataclass or Go struct.

#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 Python script that implements the resolution logic. Custom directives take priority over built-in directives of the same name:

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

Each custom directive script must export 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)

Custom directives take priority over built-in directives of the same name.