Skip to main content

Overview

The emission layer transforms TSDoc AST (Abstract Syntax Tree) into Mintlify-compatible MDX format. It handles the final rendering step, converting semantic document structures into formatted markdown with Mintlify-specific components.
Primary Component: src/markdown/CustomMarkdownEmitter.ts
Recent Enhancement: The emission layer now includes API resolution caching for improved performance during cross-reference resolution.

Key Responsibilities

AST to MDX Conversion

Transforms TSDoc AST nodes into MDX strings

Mintlify Component Generation

Creates specialized components like <ParamField> and <ResponseField>

API Resolution Caching

Caches cross-reference resolution for performance

Link Resolution

Resolves cross-references between API items

Architecture

Core Components

CustomMarkdownEmitter

Initializes with API model and caching:
Caching Integration: Automatically creates API resolution cache for improved performance
Primary method for AST to MDX conversion:
Process:
  1. Traverse TSDoc AST recursively
  2. Identify node types and apply appropriate rendering
  3. Handle special cases (tables, links, etc.)
  4. Generate Mintlify-specific components
  5. Resolve cross-references with caching
Specialized rendering for different DocNode types:

Mintlify Component Generation

Intelligent Table Conversion

The emitter’s most critical feature is intelligent table handling:
Detection Logic: Analyzes table headers and content to identify the appropriate Mintlify component
Converts property tables to <ParamField> components:
Features:
  • Type analysis with nested property support
  • Automatic required/optional detection
  • Complex type expansion
Converts method tables to <ResponseField> components:
Output Example:

API Resolution Caching

Implements intelligent caching for API resolution:
Cache Key Strategy:
Performance Benefits: 20-40% improvement for documentation with dense cross-references

Type Analysis Integration

Leverages DocumentationHelper for sophisticated type analysis:
Capabilities:
  • Recursive type analysis
  • Nested property documentation
  • Union and intersection type handling
  • Generic type parameter support
Sophisticated handling of complex TypeScript types:
Supported Patterns:
  • Nested object literals
  • Generic types with parameters
  • Union types (A | B)
  • Intersection types (A & B)
  • Array and Promise wrappers
  • Conditional types

Performance Optimization

API resolution caching provides significant performance improvements:Before Caching:
After Caching:
Measured Improvements:
  • 20-40% faster for documentation with dense cross-references
  • Significant improvement for large codebases
  • Reduced memory pressure from repeated traversals
Configurable cache settings for different use cases:
Tuning Guidelines:
  • Small Projects: 200-500 items
  • Medium Projects: 500-1000 items
  • Large Projects: 1000+ items
  • Memory-Constrained: Disable or reduce size

Error Handling and Fallbacks

Robust error handling with fallback strategies:
Fallback Hierarchy:
  1. Success: Generate proper relative link
  2. Unresolved: Use plain text with warning
  3. Error: Use plain text with error logging
Defensive programming for cache operations:
Resilience Features:
  • Cache failures don’t break resolution
  • Resolution failures are properly logged
  • Always returns valid result or throws clear error

Best Practices

Monitor Cache Performance:
Tune Cache Size:
  • Start with default (500 items)
  • Monitor hit rates during development
  • Increase size for large codebases
  • Consider memory usage vs. performance trade-offs
When to Disable:
  • Very small projects (minimal benefit)
  • Memory-constrained environments
  • Debugging resolution issues
Consistent Table Structure:
  • Maintain standard column order: Name, Type, Description
  • Use consistent header names for detection
  • Include modifier information in type column
Type Documentation:
  • Provide complete type information
  • Include examples for complex types
  • Document nested object structures
Link Resolution:
  • Use proper declaration references
  • Maintain consistent naming conventions
  • Test cross-references in generated docs

Troubleshooting

Symptoms: Tables not converted to Mintlify componentsCauses:
  • Incorrect table header format
  • Missing required columns
  • Non-standard table structure
Solutions:
  • Verify table headers match expected patterns
  • Ensure consistent column structure
  • Check detection logic in _isPropertyTable() etc.
Debugging:
Symptoms: Low cache hit rates or poor performanceCauses:
  • Cache size too small for project
  • Too many unique references
  • Cache key collisions
Solutions:
  • Increase cache size
  • Analyze reference patterns
  • Check cache key generation
  • Consider disabling for small projects
Monitoring:

Generation Layer

See how AST is constructed and emitted

Caching Layer

Learn about API resolution caching

Utilities Layer

Explore DocumentationHelper and type analysis

AST Nodes

Understand custom TSDoc nodes