Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(docs): improve Steps/StepTitle and whitespace handling in .md endpoints
Sushmithamallesha025af7b1399
diff --git a/docs/lib/source.ts b/docs/lib/source.tsindex 667a63cfc..9ea642b3a 100644--- a/docs/lib/source.ts+++ b/docs/lib/source.ts@@ -88,14 +88,14 @@ function mdxToCleanMarkdown(content: string): string {'[Video: $2](https://youtube.com/watch?v=$1)');- // Convert Callout to blockquote+ // Convert Callout to blockquote - trim content to avoid empty linesresult = result.replace(/<Callout[^>]*title="([^"]*)"[^>]*>([\s\S]*?)<\/Callout>/g,- '> **$1**: $2'+ (_, title, content) => `> **${title}**: ${content.trim()}`);result = result.replace(/<Callout[^>]*>([\s\S]*?)<\/Callout>/g,- '> $1'+ (_, content) => `> ${content.trim()}`);// Convert Card - handle multiline and various attribute orders@@ -127,9 +127,20 @@ function mdxToCleanMarkdown(content: string): string {result = result.replace(/<TabsContent[\s\S]*?value="([^"]*)"[\s\S]*?>([\s\S]*?)<\/TabsContent>/g, '\n**$1:**\n$2');result = result.replace(/<Tab[\s\S]*?value="([^"]*)"[\s\S]*?>([\s\S]*?)<\/Tab>/g, '\n**$1:**\n$2');- // Convert Steps/Step- result = result.replace(/<Step>\s*###\s*(.+)/g, '### Step: $1');- result = result.replace(/<\/?Steps?>/g, '');+ // Convert Steps/Step with StepTitle+ // Handle StepTitle with potential whitespace and multiline content+ result = result.replace(/<StepTitle>([\s\S]*?)<\/StepTitle>/g, (_, title) => {+ // Clean up the title - remove extra whitespace and any # prefix fumadocs might add+ const cleanTitle = title.replace(/^[\s#]*#\s*/, '').replace(/\s+$/, '').trim();+ return cleanTitle ? `#### ${cleanTitle}` : '';+ });+ // Handle <Step> with ### header pattern (legacy)+ result = result.replace(/<Step>\s*###\s*(.+)/g, '#### $1');+ // Remove Steps wrapper and Step tags+ result = result.replace(/<\/?Steps>/g, '');+ result = result.replace(/<\/?Step>/g, '');+ // Clean up step titles that fumadocs converted to "# title" format+ result = result.replace(/^(\s*#{1,6})\s*#\s+(.+)$/gm, '$1 $2');// Convert FrameworkOption to header with framework nameresult = result.replace(@@ -181,6 +192,68 @@ function mdxToCleanMarkdown(content: string): string {// Clean up leftover JSX artifacts like lone } or {result = result.replace(/^\s*[{}]\s*$/gm, '');+ // Normalize indentation while preserving markdown structure+ // - Code blocks: normalize by stripping common indentation prefix+ // - Nested lists/blockquotes: preserve relative indentation+ // - Other content: remove excessive leading whitespace from JSX nesting+ const lines = result.split('\n');+ const normalizedLines: string[] = [];+ let inCodeBlock = false;+ let codeBlockLines: string[] = [];++ const flushCodeBlock = () => {+ if (codeBlockLines.length > 0) {+ // Find minimum indentation (ignoring empty lines)+ const nonEmptyLines = codeBlockLines.filter(l => l.trim().length > 0);+ const minIndent = nonEmptyLines.length > 0+ ? Math.min(...nonEmptyLines.map(l => l.match(/^(\s*)/)?.[1]?.length || 0))+ : 0;+ // Strip common indentation+ for (const codeLine of codeBlockLines) {+ normalizedLines.push(codeLine.slice(minIndent));+ }+ codeBlockLines = [];+ }+ };++ for (const line of lines) {+ if (line.trim().startsWith('```')) {+ if (inCodeBlock) {+ // End of code block - normalize and flush+ flushCodeBlock();+ inCodeBlock = false;+ normalizedLines.push(line.trim());+ } else {+ // Start of code block+ inCodeBlock = true;+ normalizedLines.push(line.trim());+ }+ } else if (inCodeBlock) {+ codeBlockLines.push(line);+ } else {+ // Outside code blocks - smart whitespace handling+ const trimmedLine = line.trimStart();+ // Preserve indentation for markdown list items (but not blockquotes at root level)+ if (trimmedLine.match(/^[-*+]\s/) || trimmedLine.match(/^\d+\.\s/)) {+ // For list items, normalize to 2-space indentation levels+ const leadingSpaces = line.length - trimmedLine.length;+ const indentLevel = Math.floor(leadingSpaces / 2);+ const normalizedIndent = ' '.repeat(Math.min(indentLevel, 4)); // Cap at 4 levels+ normalizedLines.push(normalizedIndent + trimmedLine);+ } else {+ // For other content (including blockquotes), remove excessive leading whitespace+ normalizedLines.push(trimmedLine);+ }+ }+ }++ // Handle unclosed code block - flush any remaining content+ if (inCodeBlock) {+ flushCodeBlock();+ }++ result = normalizedLines.join('\n');+// Clean up excessive newlinesresult = result.replace(/\n{3,}/g, '\n\n');