-
Notifications
You must be signed in to change notification settings - Fork 8
Add an option in code blocks to ask AI about it #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for docs-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis pull request adds an "Ask AI" feature to documentation code blocks and restructures the copy button UI styling. The JavaScript implementation introduces a Sequence DiagramsequenceDiagram
actor User
participant Page
participant JavaScript
participant KapaAI
User->>Page: Page loads with code block
JavaScript->>JavaScript: Check if Kapa AI available
alt Kapa AI Available
JavaScript->>Page: Create Ask AI button + icon
JavaScript->>Page: Append to code toolbox
Note over Page: Ask AI button visible
else Kapa AI Not Available
Note over JavaScript: Skip button creation
end
User->>Page: Click Ask AI button
JavaScript->>JavaScript: Extract code from block
JavaScript->>JavaScript: Format prompt<br/>(remove $, handle continuations)
JavaScript->>KapaAI: Open with mode: ai + query
Note over KapaAI: Kapa AI processes query
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/js/06-copy-to-clipboard.js (3)
26-83: Shared tool state looks good; consider future-proofing aroundno-copyusageThe refactor to share
code,lang,copy,toast,askAI, andtoolboxand to normalize code blocks is consistent with the existing copy/run behavior and keeps the logic coherent.One consideration:
no-copynow implicitly also disables Ask AI (via the same ancestor class check). If you expect cases where AI should be available even when copying is not (or vice versa), it may be worth splitting this into more explicit flags (for example,no-copyvsno-ai) to avoid overloading one class with multiple meanings.
84-110: Ask AI button wiring is correct; watch for Kapa load timingThe Ask AI button wiring (creation, SVG icon, event handler) looks correct and mirrors the copy button structure, including reuse of the
no-copysuppression logic.One nuance: the button is only created if
window.Kapais truthy at script execution time. If Kapa is injected asynchronously after this script runs, users won’t see the button even though AI eventually becomes available. If that’s a realistic scenario, consider:
- Always rendering the button and doing the
window.Kapacheck only on click, or- Re-running the toolbox initialization (or toggling visibility) once Kapa finishes loading.
175-195:handleAskAIreuses console normalization; consider preserving visual snippet and enriching promptThe handler correctly mirrors
writeToClipboardbehavior: trimming trailing spaces, normalizing console snippets viaextractCommands, and then opening Kapa with a Markdown-formatted prompt. This alignment reduces surprises between “copy” and “ask AI”.Two potential improvements:
Preserve the exact visual snippet for AI
For console blocks,extractCommandsflattens multi-line$prompts into a single&&-chained command string. That’s great for copying into a shell, but users might expect the AI prompt to match what they see on the page (including$prompts and line breaks). You could:
- Use the raw
textfor Ask AI, or- Include both, for example:
var aiPromptText = 'Explain this console snippet (shown as run commands below):\n\n' + 'Original snippet:\n\n```\n' + code.innerText.replace(TRAILING_SPACE_RX, '') + '\n```\n\n' + 'Commands:\n\n```\n' + extractCommands(text) + '\n```'Add minimal API robustness
Before callingkapa.open, consider guarding against unexpected API shape to avoid runtime errors if the integration changes:if (kapa && typeof kapa.open === 'function') { kapa.open({ mode: 'ai', query: aiPromptText, submit: true }) } else { console.warn('Kapa AI is not available or misconfigured.') }These are non-blocking but would make the integration more resilient and the AI explanation closer to what users see.
src/css/doc.css (2)
1490-1513: Inline-flex copy button + hover transitions look consistent with toolbox layoutSwitching
.copy-buttontoinline-flexwithposition: relativeand adding smooth hover transitions for SVG/img icons fits well with the existing.source-toolboxflex layout and supports the new toast positioning.One thing to keep in mind: both
.copy-buttonand.ask-ai-buttonsetoutline: none;, which removes the default keyboard focus indicator. This was already the case for copy, but it now extends to the new AI control as well. If keyboard accessibility is a concern, consider reintroducing a visible focus style (e.g., a focus ring or underline) instead of globally suppressing outline.
1563-1590: Ask AI button/icon styling aligns with copy button; spacing may need fine-tuningThe
.ask-ai-buttonand.ask-ai-iconstyles mirror the copy button’s structure and sizing, and the hover color transition on the sparkles path nicely matches the copy icon behavior. This should integrate cleanly into.source-toolboxalongside the language label and run/copy buttons.If, during visual QA, the icons or separators feel cramped (e.g., “Copy | Ask AI” touching too closely), consider a small horizontal gap or padding between adjacent buttons, but that’s purely cosmetic and can be tuned later.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/css/doc.css(2 hunks)src/js/06-copy-to-clipboard.js(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
src/css/doc.css (1)
1519-1556: Copy icon hover and toast positioning are well-structured; verify overflow contextsThe new hover styles for SVG and image copy icons, plus the reworked
.copy-toastpositioning (absolute below the button, centered with a small margin and arrow), make the interaction clearer and avoid pointer interference viapointer-events: none.Given
.source-toolboxis absolutely positioned within.listingblock > .content, the toast should appear just below the icon without disturbing layout. The only thing worth double-checking in the browser is that no ancestor (e.g., the code container) hasoverflow: hiddenthat could clip the toast/arrow—especially in narrow viewports or responsive layouts.
micheleRP
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!

This pull request adds a new "Ask AI" feature to code blocks in documentation, allowing users to quickly query Kapa AI for code explanations. It also refines the UI/UX for the existing "Copy" functionality and improves the styling and positioning of toolbox elements for better accessibility and visual feedback.
New Feature: Ask AI Integration
UI/UX Improvements for Toolbox Buttons
.copy-buttonand new.ask-ai-buttonto useinline-flexfor better alignment and interaction, and added hover effects for both SVG and image icons for improved feedback. [1] [2]Code Refactoring
src/js/06-copy-to-clipboard.jsfor maintainability. [1] [2]2025-11-18_11-43-49.mp4