Private/Export-ToMarkdown.ps1

function Export-ToMarkdown {
    <#
    .SYNOPSIS
        Exports module data to Markdown format optimized for LLM consumption.
    #>

    param(
        [Parameter(Mandatory = $true)]
        [PSCustomObject]$ModuleData,
        
        [Parameter(Mandatory = $true)]
        [string]$OutputPath
    )
    
    # Add StringBuilder for better performance with large datasets
    $sb = [System.Text.StringBuilder]::new()
    
    [void]$sb.AppendLine("# PowerShell Module: $($ModuleData.ModuleName)")
    [void]$sb.AppendLine()
    [void]$sb.AppendLine("**Version:** $($ModuleData.ModuleVersion) ")
    [void]$sb.AppendLine("**Commands:** $($ModuleData.ExportedCommands) ")
    [void]$sb.AppendLine("**Generated:** $($ModuleData.GeneratedOn) ")
    [void]$sb.AppendLine()
    [void]$sb.AppendLine("## Command Types")
    $ModuleData.CommandTypes | ForEach-Object { [void]$sb.AppendLine("- $_") }
    [void]$sb.AppendLine()
    [void]$sb.AppendLine("## Commands")
    [void]$sb.AppendLine()
    
    foreach ($command in $ModuleData.Commands) {
        [void]$sb.AppendLine("### $($command.Name)")
        [void]$sb.AppendLine()
        [void]$sb.AppendLine("**Type:** $($command.CommandType) ")
        [void]$sb.AppendLine("**Synopsis:** $($command.Synopsis)")
        [void]$sb.AppendLine()
        [void]$sb.AppendLine("**Description:** ")
        [void]$sb.AppendLine($command.Description)
        [void]$sb.AppendLine()
        
        if ($command.Parameters -and $command.Parameters.Count -gt 0) {
            [void]$sb.AppendLine("**Parameters:**")
            foreach ($param in $command.Parameters) {
                $required = if ($param.Required) { " (Required)" } else { "" }
                [void]$sb.AppendLine("- **$($param.Name)** [$($param.Type)]$required - $($param.Description)")
            }
            [void]$sb.AppendLine()
        }
        
        if ($command.Examples -and $command.Examples.Count -gt 0) {
            [void]$sb.AppendLine("**Examples:**")
            foreach ($example in $command.Examples) {
                [void]$sb.AppendLine()
                [void]$sb.AppendLine("**$($example.Title)**")
                [void]$sb.AppendLine('```powershell')
                [void]$sb.AppendLine($example.Code)
                [void]$sb.AppendLine('```')
                [void]$sb.AppendLine($example.Remarks)
                [void]$sb.AppendLine()
            }
        }
        
        [void]$sb.AppendLine("---")
        [void]$sb.AppendLine()
    }
    
    # Write to file
    Set-Content -Path $OutputPath -Value $sb.ToString() -Encoding UTF8
}