Skip to content

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

docs: preserve mermaid diagrams in LLM markdown output

Sushmitha Malleshf4643dd93daf
diff --git a/docs/lib/source.ts b/docs/lib/source.ts
index 38b5f5713..210d9583e 100644
--- a/docs/lib/source.ts
+++ b/docs/lib/source.ts
@@ -397,7 +397,27 @@ ${page.data.description || ''}`;
${page.data.description || ''}`;
}
- const cleanContent = mdxToCleanMarkdown(content);
+ // Split content at Mermaid tags, process each segment separately, then rejoin
+ // with mermaid code blocks. This prevents JSX regexes with [\s\S]*? from
+ // matching across mermaid boundaries and consuming diagram content.
+ const mermaidRegex = /<Mermaid\s+chart="([\s\S]*?)"\s*\/>/g;
+ const segments: string[] = [];
+ const mermaidCharts: string[] = [];
+ let lastIndex = 0;
+ let match;
+
+ while ((match = mermaidRegex.exec(content)) !== null) {
+ segments.push(content.slice(lastIndex, match.index));
+ mermaidCharts.push(match[1]);
+ lastIndex = match.index + match[0].length;
+ }
+ segments.push(content.slice(lastIndex));
+
+ const cleanSegments = segments.map(s => mdxToCleanMarkdown(s));
+ let cleanContent = cleanSegments[0];
+ for (let i = 0; i < mermaidCharts.length; i++) {
+ cleanContent += `\n\n\`\`\`mermaid\n${mermaidCharts[i]}\n\`\`\`\n\n${cleanSegments[i + 1]}`;
+ }
const footer = includeFooter
? `\n\n---\n\n📚 **More documentation:** [View all docs](https://docs.composio.dev/llms.txt) | [Glossary](https://docs.composio.dev/llms.mdx/docs/glossary) | [Cookbooks](https://docs.composio.dev/llms.mdx/cookbooks) | [API Reference](https://docs.composio.dev/llms.mdx/reference)`