Skip to content

Conversation

@pwizla
Copy link
Collaborator

@pwizla pwizla commented Aug 13, 2025

This PR adds an "Ask AI" button to codeblocks, next to the Copy and Wrap buttons.
When clicked, the button automatically opens the Kapa AI modal with a prefilled prompt that asks to explain the code, and you'll quickly get an answer. With follow-up questions you can now get tailored explanations and examples for your use case.

contextual-ai-for-codeblocks.mp4

To achieve this, we swizzled the core code block component from Docusaurus and inject a button in the button group, but only after checking that the code block is "worth it": We're excluding short code blocks (cutoff currently set at 30 characters) and some 'basic' commands such as npm install, yarn add, etc.
All of these are configurable directly within the /src/theme/CodeBlock/index.js file.

⚠️ Please note that, if you visit the Vercel Preview link, you will probably get "An error occured" message in the modal when clicking the button. This is not a bug. This is because Kapa filters URLs. It will work only locally if you clone the branch on your machine, or on the official docs.strapi.io website when merged into main.

@pwizla pwizla added this to the 6.8.0 milestone Aug 13, 2025
@pwizla pwizla requested a review from meganelacheny August 13, 2025 14:53
@pwizla pwizla self-assigned this Aug 13, 2025
@pwizla pwizla added source: repo PRs/issues not targeting a specific documentation but rather affecting the whole repo pr: new content PRs for new product features or new documentation sections labels Aug 13, 2025
@vercel
Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
documentation Ready Ready Preview Comment Sep 1, 2025 3:40pm
pwizla added 3 commits August 13, 2025 16:56
since we simplified the architecture and only "swizzle" the default Code block from Docusaurus 3.x
@pwizla pwizla added the flag: don't merge This PR should not be merged at the moment label Aug 13, 2025
@pwizla pwizla removed the flag: don't merge This PR should not be merged at the moment label Sep 3, 2025
@pwizla pwizla merged commit 34dc43d into main Sep 3, 2025
4 of 5 checks passed
@pwizla pwizla deleted the repo/contextual-ai-codeblocks branch September 3, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new content PRs for new product features or new documentation sections source: repo PRs/issues not targeting a specific documentation but rather affecting the whole repo

1 participant