Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 04:30 UTC
docs: rewrite prompt code extraction to fix Radix tab leak
- Walk up from pre to step boundary only (not past it) to find tab panels - Match tab panel to trigger by index position in sibling panels/tabs - Improve language detection (data-language, data-lang, content heuristics) - Broader step title selector (h2-h4, class patterns) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sushmitha Mallesh committed
Mar 6, 2026 at 23:57 UTC
cb6e1172ed900d7a0c61d5b1ac4636047f435816
1 file changed
+39
-19
docs/components/quickstart/prompt-banner.tsx
+39
-19
@@ -12,18 +12,43 @@ export function PromptBanner({ children }: PromptBannerProps) {
12
const contentRef = useRef<HTMLDivElement>(null);
13
14
const detectLang = (pre: Element): string => {
15
- // Check data-language on <pre> or <code>
15
const code = pre.querySelector('code');
17
- const dataLang = pre.getAttribute('data-language') ?? code?.getAttribute('data-language');
18
- if (dataLang) return dataLang;
16
+ // Check data-language attribute (set by Shiki)
17
+ for (const el of [pre, code]) {
18
+ const lang = el?.getAttribute('data-language') ?? el?.getAttribute('data-lang');
19
+ if (lang) return lang;
20
+ }
21
// Check class="language-xxx"
22
const cls = Array.from(code?.classList ?? []).find(c => c.startsWith('language-'));
23
if (cls) return cls.replace('language-', '');
24
// Guess from content
25
const text = code?.textContent ?? '';
24
- if (text.includes('pip install') || text.includes('npm install')) return 'bash';
25
- if (text.includes('import ') && text.includes('from ')) return 'python';
26
- if (text.includes('import ') && text.includes('from "')) return 'typescript';
26
+ if (/^(pip|npm|npx|bun|yarn|pnpm) /.test(text.trim())) return 'bash';
27
+ if (text.includes('from dotenv') || text.includes('import asyncio')) return 'python';
28
+ if (text.includes('from "') || text.includes('from "@')) return 'typescript';
29
+ if (text.includes('COMPOSIO_API_KEY=')) return 'bash';
30
+ return '';
31
+ };
32
+
33
+ const getTabLabel = (pre: Element, step: Element): string => {
34
+ // Find the nearest tab panel that is INSIDE the step (not an ancestor)
35
+ let el: Element | null = pre.parentElement;
36
+ while (el && el !== step) {
37
+ if (el.getAttribute('role') === 'tabpanel') {
38
+ // Found a tab panel inside the step — find its trigger button
39
+ const tablist = el.parentElement?.querySelector('[role="tablist"]');
40
+ if (tablist) {
41
+ const tabs = tablist.querySelectorAll('[role="tab"]');
42
+ const panels = el.parentElement?.querySelectorAll(':scope > [role="tabpanel"]');
43
+ if (panels) {
44
+ const idx = Array.from(panels).indexOf(el);
45
+ if (idx >= 0 && tabs[idx]) return tabs[idx].textContent?.trim() ?? '';
46
+ }
47
+ }
48
+ return '';
49
+ }
50
+ el = el.parentElement;
51
+ }
52
return '';
53
};
54
@@ -32,25 +57,20 @@ export function PromptBanner({ children }: PromptBannerProps) {
57
const steps = stepsEl.querySelectorAll('.fd-step');
58
59
steps.forEach((step) => {
35
- // Step title
36
- const title = step.querySelector('h3, h4, [class*="StepTitle"]');
37
- if (title) parts.push(`### ${title.textContent?.trim()}`);
60
+ // Step title — try multiple selectors
61
+ const title = step.querySelector('h3, h4, h2, [class*="step-title"], [class*="StepTitle"]');
62
+ const titleText = title?.textContent?.trim();
63
+ if (titleText) parts.push(`### ${titleText}`);
64
39
- // Find code blocks, checking if they're inside tabs
65
+ // Extract code blocks with tab labels
66
const pres = step.querySelectorAll('pre');
67
pres.forEach((pre) => {
42
- const lang = detectLang(pre);
68
const code = pre.querySelector('code')?.textContent?.trim() ?? '';
69
if (!code) return;
70
46
- // Check if inside a tab panel — find the matching tab trigger for the label
47
- const tabPanel = pre.closest('[role="tabpanel"]');
48
- let tabLabel = '';
49
- if (tabPanel) {
50
- const labelledBy = tabPanel.getAttribute('aria-labelledby') ?? '';
51
- const trigger = labelledBy ? document.getElementById(labelledBy) : null;
52
- tabLabel = trigger?.textContent?.trim() ?? '';
53
- }
71
+ const lang = detectLang(pre);
72
+ const tabLabel = getTabLabel(pre, step);
73
+
74
if (tabLabel) {
75
parts.push(`**${tabLabel}**\n\n\`\`\`${lang}\n${code}\n\`\`\``);
76
} else {