@devries-cameron20 / composio-1 / commits / a025af7b1
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(docs): improve Steps/StepTitle and whitespace handling in .md endpoints

Fixes several issues with the .md endpoint conversion: 1. StepTitle conversion - handle fumadocs processed content where `# title` format is used, producing clean `#### Title` headers 2. Code block normalization - strip common indentation prefix from code block content, and handle unclosed code blocks by flushing remaining content at end of processing 3. Smart whitespace handling: - Preserve relative indentation for nested markdown lists - Remove excessive leading whitespace from other content - Normalize list item indentation to 2-space levels 4. Callout conversion - trim content to avoid empty lines in blockquotes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Sushmithamallesh committed Jan 28, 2026 at 01:08 UTC a025af7b1399abe58d1c6fcbefebbfe51b612ed0
1 file changed +79 -6
docs/lib/source.ts
+79 -6
@@ -88,14 +88,14 @@ function mdxToCleanMarkdown(content: string): string {
88 '[Video: $2](https://youtube.com/watch?v=$1)'
89 );
90
91 - // Convert Callout to blockquote
91 + // Convert Callout to blockquote - trim content to avoid empty lines
92 result = result.replace(
93 /<Callout[^>]*title="([^"]*)"[^>]*>([\s\S]*?)<\/Callout>/g,
94 - '> **$1**: $2'
94 + (_, title, content) => `> **${title}**: ${content.trim()}`
95 );
96 result = result.replace(
97 /<Callout[^>]*>([\s\S]*?)<\/Callout>/g,
98 - '> $1'
98 + (_, content) => `> ${content.trim()}`
99 );
100
101 // Convert Card - handle multiline and various attribute orders
@@ -127,9 +127,20 @@ function mdxToCleanMarkdown(content: string): string {
127 result = result.replace(/<TabsContent[\s\S]*?value="([^"]*)"[\s\S]*?>([\s\S]*?)<\/TabsContent>/g, '\n**$1:**\n$2');
128 result = result.replace(/<Tab[\s\S]*?value="([^"]*)"[\s\S]*?>([\s\S]*?)<\/Tab>/g, '\n**$1:**\n$2');
129
130 - // Convert Steps/Step
131 - result = result.replace(/<Step>\s*###\s*(.+)/g, '### Step: $1');
132 - result = result.replace(/<\/?Steps?>/g, '');
130 + // Convert Steps/Step with StepTitle
131 + // Handle StepTitle with potential whitespace and multiline content
132 + result = result.replace(/<StepTitle>([\s\S]*?)<\/StepTitle>/g, (_, title) => {
133 + // Clean up the title - remove extra whitespace and any # prefix fumadocs might add
134 + const cleanTitle = title.replace(/^[\s#]*#\s*/, '').replace(/\s+$/, '').trim();
135 + return cleanTitle ? `#### ${cleanTitle}` : '';
136 + });
137 + // Handle <Step> with ### header pattern (legacy)
138 + result = result.replace(/<Step>\s*###\s*(.+)/g, '#### $1');
139 + // Remove Steps wrapper and Step tags
140 + result = result.replace(/<\/?Steps>/g, '');
141 + result = result.replace(/<\/?Step>/g, '');
142 + // Clean up step titles that fumadocs converted to "# title" format
143 + result = result.replace(/^(\s*#{1,6})\s*#\s+(.+)$/gm, '$1 $2');
144
145 // Convert FrameworkOption to header with framework name
146 result = result.replace(
@@ -181,6 +192,68 @@ function mdxToCleanMarkdown(content: string): string {
192 // Clean up leftover JSX artifacts like lone } or {
193 result = result.replace(/^\s*[{}]\s*$/gm, '');
194
195 + // Normalize indentation while preserving markdown structure
196 + // - Code blocks: normalize by stripping common indentation prefix
197 + // - Nested lists/blockquotes: preserve relative indentation
198 + // - Other content: remove excessive leading whitespace from JSX nesting
199 + const lines = result.split('\n');
200 + const normalizedLines: string[] = [];
201 + let inCodeBlock = false;
202 + let codeBlockLines: string[] = [];
203 +
204 + const flushCodeBlock = () => {
205 + if (codeBlockLines.length > 0) {
206 + // Find minimum indentation (ignoring empty lines)
207 + const nonEmptyLines = codeBlockLines.filter(l => l.trim().length > 0);
208 + const minIndent = nonEmptyLines.length > 0
209 + ? Math.min(...nonEmptyLines.map(l => l.match(/^(\s*)/)?.[1]?.length || 0))
210 + : 0;
211 + // Strip common indentation
212 + for (const codeLine of codeBlockLines) {
213 + normalizedLines.push(codeLine.slice(minIndent));
214 + }
215 + codeBlockLines = [];
216 + }
217 + };
218 +
219 + for (const line of lines) {
220 + if (line.trim().startsWith('```')) {
221 + if (inCodeBlock) {
222 + // End of code block - normalize and flush
223 + flushCodeBlock();
224 + inCodeBlock = false;
225 + normalizedLines.push(line.trim());
226 + } else {
227 + // Start of code block
228 + inCodeBlock = true;
229 + normalizedLines.push(line.trim());
230 + }
231 + } else if (inCodeBlock) {
232 + codeBlockLines.push(line);
233 + } else {
234 + // Outside code blocks - smart whitespace handling
235 + const trimmedLine = line.trimStart();
236 + // Preserve indentation for markdown list items (but not blockquotes at root level)
237 + if (trimmedLine.match(/^[-*+]\s/) || trimmedLine.match(/^\d+\.\s/)) {
238 + // For list items, normalize to 2-space indentation levels
239 + const leadingSpaces = line.length - trimmedLine.length;
240 + const indentLevel = Math.floor(leadingSpaces / 2);
241 + const normalizedIndent = ' '.repeat(Math.min(indentLevel, 4)); // Cap at 4 levels
242 + normalizedLines.push(normalizedIndent + trimmedLine);
243 + } else {
244 + // For other content (including blockquotes), remove excessive leading whitespace
245 + normalizedLines.push(trimmedLine);
246 + }
247 + }
248 + }
249 +
250 + // Handle unclosed code block - flush any remaining content
251 + if (inCodeBlock) {
252 + flushCodeBlock();
253 + }
254 +
255 + result = normalizedLines.join('\n');
256 +
257 // Clean up excessive newlines
258 result = result.replace(/\n{3,}/g, '\n\n');
259