CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pydoc-markdown

Create Python API documentation in Markdown format

Pending
Overview
Eval results
Files

docstring-processing.mddocs/

Docstring Processing

Comprehensive docstring transformation and enhancement through configurable processors that filter content, resolve cross-references, and convert between documentation formats.

Capabilities

Filter Processing

Removes module and class members based on configurable criteria including visibility, documentation status, and custom expressions.

class FilterProcessor(Processor):
    """
    Filter processor removes API objects based on specified criteria.
    
    Attributes:
        expression: Python expression evaluated with variables 'name', 'obj', and 'default()'
                   to determine if object should be kept (default: None)
        documented_only: Only include objects with docstrings (default: True)
        do_not_filter_modules: Never filter out modules (default: False)  
        skip_empty_modules: Remove modules with no remaining members after filtering (default: True)
    """
    expression: Optional[str]
    documented_only: bool
    do_not_filter_modules: bool
    skip_empty_modules: bool
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Apply filtering rules to remove unwanted API objects.
        
        Args:
            modules: List of modules to filter
            resolver: Optional resolver for cross-references
        """

Cross-Reference Processing

Processes cross-references in docstrings, converting references to other API objects into hyperlinks.

class CrossrefProcessor(Processor):
    """
    Process cross-references in docstrings and convert them to hyperlinks.
    
    Attributes:
        resolver_v2: Optional resolver for reference resolution (default: None)
    """
    resolver_v2: Optional[ResolverV2]
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Process cross-references in docstrings.
        
        Args:
            modules: List of modules to process
            resolver: Resolver for converting references to hyperlinks
        """

Google Style Processing

Converts Google-style docstrings to Markdown format with proper argument, return value, and exception documentation.

class GoogleProcessor(Processor):
    """
    Process Google-style docstrings and convert them to Markdown.
    
    Handles sections like Args:, Returns:, Raises:, Yields:, Note:, Example:
    """
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Convert Google-style docstrings to Markdown format.
        
        Args:
            modules: List of modules to process
            resolver: Optional resolver for cross-references
        """

Sphinx Style Processing

Converts Sphinx-style docstrings (reStructuredText) to Markdown format with proper formatting of parameters, return values, and other documentation elements.

class SphinxProcessor(Processor):
    """
    Process Sphinx-style docstrings and convert them to Markdown.
    
    Handles reStructuredText directives like :param:, :returns:, :raises:, etc.
    """
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Convert Sphinx-style docstrings to Markdown format.
        
        Args:
            modules: List of modules to process  
            resolver: Optional resolver for cross-references
        """

Smart Processing

Applies intelligent formatting and enhancements to docstrings including code block detection, list formatting, and automatic improvements.

class SmartProcessor(Processor):
    """
    Apply smart formatting enhancements to docstrings.
    
    Automatically detects and formats code blocks, lists, and other common
    documentation patterns for improved Markdown output.
    """
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Apply smart formatting to docstrings.
        
        Args:
            modules: List of modules to process
            resolver: Optional resolver for cross-references  
        """

Pydoc-Markdown Style Processing

Processes Pydoc-Markdown's native docstring format with custom extensions and formatting rules.

class PydocmdProcessor(Processor):
    """
    Process Pydoc-Markdown native docstring format.
    
    Handles custom Pydoc-Markdown syntax and formatting extensions.
    """
    
    def process(self, modules: List[docspec.Module], resolver: Optional[Resolver]) -> None:
        """
        Process Pydoc-Markdown format docstrings.
        
        Args:
            modules: List of modules to process
            resolver: Optional resolver for cross-references
        """

Usage Examples

Basic Filtering

from pydoc_markdown import PydocMarkdown
from pydoc_markdown.contrib.processors.filter import FilterProcessor

# Only include documented public members
processor = FilterProcessor(
    documented_only=True,
    expression="not name.startswith('_')"
)

config = PydocMarkdown(processors=[processor])

Advanced Filtering

from pydoc_markdown.contrib.processors.filter import FilterProcessor

# Complex filtering with custom expression
processor = FilterProcessor(
    expression="not name.startswith('_') and 'deprecated' not in (obj.docstring or '').lower()",
    documented_only=True,
    skip_empty_modules=True
)

Cross-Reference Processing

from pydoc_markdown.contrib.processors.crossref import CrossrefProcessor

# Enable cross-reference resolution
processor = CrossrefProcessor()

config = PydocMarkdown(processors=[processor])

Google Style Docstrings

from pydoc_markdown.contrib.processors.google import GoogleProcessor

# Convert Google-style docstrings
processor = GoogleProcessor()

# Example docstring it processes:
"""
Calculate the area of a rectangle.

Args:
    width (float): The width of the rectangle.
    height (float): The height of the rectangle.

Returns:
    float: The area of the rectangle.

Raises:
    ValueError: If width or height is negative.
"""

Sphinx Style Docstrings

from pydoc_markdown.contrib.processors.sphinx import SphinxProcessor

# Convert Sphinx-style docstrings  
processor = SphinxProcessor()

# Example docstring it processes:
"""
Calculate the area of a rectangle.

:param width: The width of the rectangle
:type width: float
:param height: The height of the rectangle  
:type height: float
:returns: The area of the rectangle
:rtype: float
:raises ValueError: If width or height is negative
"""

Combined Processing Pipeline

from pydoc_markdown import PydocMarkdown
from pydoc_markdown.contrib.processors.filter import FilterProcessor
from pydoc_markdown.contrib.processors.google import GoogleProcessor
from pydoc_markdown.contrib.processors.smart import SmartProcessor
from pydoc_markdown.contrib.processors.crossref import CrossrefProcessor

# Comprehensive processor pipeline
config = PydocMarkdown(
    processors=[
        FilterProcessor(
            documented_only=True,
            expression="not name.startswith('_') and default()"
        ),
        GoogleProcessor(),  # Convert Google-style docstrings
        SmartProcessor(),   # Apply smart formatting
        CrossrefProcessor()  # Resolve cross-references
    ]
)

Configuration Examples

YAML Configuration

processors:
  # Filter undocumented and private members
  - type: filter
    documented_only: true
    expression: "not name.startswith('_') and default()"
    skip_empty_modules: true
    
  # Convert Google-style docstrings
  - type: google
  
  # Apply smart formatting  
  - type: smart
  
  # Resolve cross-references
  - type: crossref

Advanced Filtering Configuration

processors:
  - type: filter
    # Custom expression for complex filtering
    expression: |
      (not name.startswith('_')) and 
      ('deprecated' not in (obj.docstring or '').lower()) and
      (not hasattr(obj, 'decorations') or 
       not any(d.name == 'private' for d in (obj.decorations or []))) and
      default()
    documented_only: true
    do_not_filter_modules: false
    skip_empty_modules: true

Docstring Format Specific Processing

# For Google-style docstrings
processors:
  - type: filter
  - type: google
  - type: smart  
  - type: crossref

# For Sphinx-style docstrings  
processors:
  - type: filter
  - type: sphinx
  - type: smart
  - type: crossref

# For mixed formats
processors:
  - type: filter
  - type: google
  - type: sphinx  
  - type: pydocmd
  - type: smart
  - type: crossref

Processing Order

The order of processors matters. Recommended processing pipeline:

  1. FilterProcessor: Remove unwanted objects early
  2. Format Processors: Convert docstring formats (google/sphinx/pydocmd)
  3. SmartProcessor: Apply intelligent formatting enhancements
  4. CrossrefProcessor: Resolve cross-references last (after all content is formatted)
processors = [
    FilterProcessor(),      # 1. Filter content
    GoogleProcessor(),      # 2. Convert docstring format
    SmartProcessor(),       # 3. Apply smart formatting
    CrossrefProcessor()     # 4. Resolve cross-references
]

Install with Tessl CLI

npx tessl i tessl/pypi-pydoc-markdown

docs

cli-interface.md

docstring-processing.md

documentation-rendering.md

index.md

main-config.md

plugin-interfaces.md

python-loading.md

utility-functions.md

tile.json