Skip to content

Docs text

docs_text

Text renderer for ast_docs output.

Renders the :func:format_docs_json payload as compact human-readable text for the LLM, mirroring the glyph/header conventions of the sibling *_text renderers. Full-detail content (README, mkdocs, page bodies) is reproduced verbatim — no truncation; the compaction is purely the removal of JSON key/quote/escape overhead.

render_docs_text(data, detail)

Render docs data as compact text for a given detail level.

Parameters:

Name Type Description Default
data dict[str, object]

Payload from :func:format_docs_json.

required
detail str

Detail level — toc, summary, or full.

required

Returns:

Type Description
str

Compact text rendering. Full bodies are reproduced verbatim.

Source code in packages/axm-ast/src/axm_ast/tools/docs_text.py
Python
def render_docs_text(data: dict[str, object], detail: str) -> str:
    """Render docs data as compact text for a given detail level.

    Args:
        data: Payload from :func:`format_docs_json`.
        detail: Detail level — ``toc``, ``summary``, or ``full``.

    Returns:
        Compact text rendering. Full bodies are reproduced verbatim.
    """
    typed = cast("_DocsData", data)
    pages = typed.get("pages") or []
    project = typed.get("project", "project")
    readme = typed.get("readme")
    mkdocs = typed.get("mkdocs")
    extras = (1 if readme else 0) + (1 if mkdocs else 0)
    header = f"ast_docs | {detail} | {project} | {len(pages)} pages +{extras}"

    lines: list[str] = [header]
    _append_file(lines, "\U0001f4d6", readme)
    _append_file(lines, "⚙", mkdocs)
    _append_tree(lines, typed.get("tree"))
    for page in pages:
        _append_page(lines, page, detail)
    return "\n".join(lines)