Overview
Renderers transform context fragments into different output formats. All renderers extend the abstractContextRenderer base class and implement the same interface.
Base Class
ContextRenderer
Abstract base class implementing the Template Method pattern.RendererOptions
RenderContext
XmlRenderer
Renders fragments as XML with proper nesting, escaping, and indentation.Constructor
render()
fragments- Array of context fragments to render
- XML string with 2-space indentation
Features
XML Escaping
XML Escaping
Automatically escapes special characters:
| Character | Escaped |
|---|---|
& | & |
< | < |
> | > |
" | " |
' | ' |
Array Handling
Array Handling
Arrays are singularized and wrapped:
Nested Objects
Nested Objects
Objects are recursively rendered:
Multiline Text
Multiline Text
Multiline values are indented:
MarkdownRenderer
Renders fragments as human-readable Markdown with bullet points and headers.Constructor
render()
fragments- Array of context fragments to render
- Markdown string with headers and bullet points
Features
Headers
Headers
Top-level fragments use
## headers:Bullet Lists
Bullet Lists
Nested structures use indented bullet points:
Title Casing
Title Casing
Fragment names are automatically title-cased:
TomlRenderer
Renders fragments as TOML-like configuration format.Constructor
render()
fragments- Array of context fragments to render
- TOML-formatted string
Features
Section Headers
Section Headers
Top-level fragments become sections:
Nested Sections
Nested Sections
Nested objects use dotted notation:
Arrays
Arrays
Arrays use inline format:
Type Preservation
Type Preservation
Preserves types in output:
ToonRenderer
Renders fragments as Token-Oriented Object Notation (TOON), a compact format optimized for token efficiency.Constructor
render()
fragments- Array of context fragments to render
- TOON-formatted string
Features
YAML-like Hierarchy
YAML-like Hierarchy
Uses indentation for structure:
Primitive Arrays
Primitive Arrays
Compact comma-separated format:
Tabular Arrays
Tabular Arrays
Uniform object arrays as CSV tables:Format:
name[length]{fields}:Automatic Quoting
Automatic Quoting
Only quotes when necessary:
Null Handling
Null Handling
Represents null explicitly:
TOON Format Specification
- Primitives
- Objects
- Arrays
- Complex
Utility Methods
sanitizeFragments()
Remove null/undefined values recursively.groupByName()
Group fragments by name.isPrimitive()
Check if data is a primitive value.Custom Renderers
Create custom renderers by extendingContextRenderer:
Render Helper
Convenience function for quick XML rendering:tag- Parent tag namefragments- Fragments to render
- XML string with fragments wrapped in parent tag
Choosing a Renderer
XmlRenderer
Best for models that prefer structured XML (e.g., Claude)
- Hierarchical structure
- Proper escaping
- 2-space indentation
MarkdownRenderer
Best for human-readable output
- Headers and bullet points
- Natural reading flow
- Good for documentation
TomlRenderer
Best for configuration-style data
- Section-based structure
- Type preservation
- Between XML and YAML complexity
Next Steps
Fragment Builders
Complete fragment builder API reference
StreamStore API
Complete stream storage API reference
Renderers Guide
Learn about using renderers
Domain Knowledge
Learn about domain fragments