Skip to main content
Glama
markdown-generator.ts2.88 kB
import { AnalysisResult, CodeElement } from '../types/index.js'; export class MarkdownGenerator { generateDocumentation(results: AnalysisResult[]): string { const sections: string[] = []; sections.push('# Codebase Documentation\n'); sections.push(this.generateSummary(results)); for (const result of results) { sections.push(this.generateFileDocumentation(result)); } return sections.join('\n\n'); } private generateSummary(results: AnalysisResult[]): string { const totalFiles = results.length; const totalElements = results.reduce((sum, r) => sum + r.totalElements, 0); const totalDocumented = results.reduce((sum, r) => sum + r.documentedElements, 0); const avgCoverage = totalElements > 0 ? (totalDocumented / totalElements) * 100 : 0; const lines: string[] = [ '## Summary', '', `- **Total Files Analyzed**: ${totalFiles}`, `- **Total Code Elements**: ${totalElements}`, `- **Documented Elements**: ${totalDocumented}`, `- **Documentation Coverage**: ${avgCoverage.toFixed(2)}%`, '' ]; return lines.join('\n'); } private generateFileDocumentation(result: AnalysisResult): string { const lines: string[] = [ `## ${result.filePath}`, '', `**Language**: ${result.language} `, `**Coverage**: ${result.documentationCoverage}%`, '' ]; // Group elements by type const byType = this.groupByType(result.elements); for (const [type, elements] of Object.entries(byType)) { lines.push(`### ${this.capitalizeType(type)}`); lines.push(''); for (const element of elements) { lines.push(this.generateElementDoc(element)); } } return lines.join('\n'); } private generateElementDoc(element: CodeElement): string { const lines: string[] = []; lines.push(`#### \`${element.name}\``); lines.push(''); if (element.signature) { lines.push('```' + (element.filePath.endsWith('.py') ? 'python' : 'typescript')); lines.push(element.signature); lines.push('```'); lines.push(''); } if (element.hasDocumentation && element.documentation) { lines.push(element.documentation); } else { lines.push('*No documentation available*'); } lines.push(''); lines.push(`**Location**: Line ${element.line}`); lines.push(''); return lines.join('\n'); } private groupByType(elements: CodeElement[]): Record<string, CodeElement[]> { const groups: Record<string, CodeElement[]> = {}; for (const element of elements) { if (!groups[element.type]) { groups[element.type] = []; } groups[element.type].push(element); } return groups; } private capitalizeType(type: string): string { return type.charAt(0).toUpperCase() + type.slice(1) + 's'; } }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Njengah/claude-4.5-mcp-tutorial'

If you have feedback or need assistance with the MCP directory API, please join our Discord server