TYPESCRIPT · ASTRO & MDX
GitHub ↗
astro-rehype-nano-code — Interactive Code Block Annotations & AI Walkthroughs
astro-rehype-nano-code is a Rehype plugin for Astro that enriches Markdown and MDX code blocks with complexity badges and line-by-line interactive explanations. Readers can click any code snippet in your documentation to get an instant, zero-latency breakdown powered by local browser AI.
$ npm install astro-rehype-nano-code
01. Architectural Specifications
STATUS: PRODUCTION READY
[ 01 // CAPABILITY ]
Zero Static Bloat
Eliminates heavy static markdown code commentary from initial HTML payloads by generating line-level notes on-demand.
[ 02 // CAPABILITY ]
Build-Time Rehype Transformer
Attaches data-code-raw and data-lang attributes during markdown processing with zero runtime overhead.
[ 03 // CAPABILITY ]
Streaming Annotations
Uses Gemini Nano promptStreaming to deliver real-time, line-by-line code breakdowns directly in the browser.
02. Implementation & Usage
BUN / ASTRO 5+
// Installation
CLI
bun add astro-rehype-nano-code
# or
pnpm add astro-rehype-nano-code
// Configuration
astro.config.mjs
// astro.config.mjs
import { defineConfig } from "astro/config";
import rehypeNanoCode from "astro-rehype-nano-code";
export default defineConfig({
integrations: [
rehypeNanoCode({
collapsible: true,
languages: ["ts", "js", "astro", "rust", "python"],
autoInjectCustomElement: true
})
]
});
// Chrome Built-in AI Prerequisites
- 1. Open
chrome://flagsin Google Chrome 128+ - 2. Set
#prompt-api-for-gemini-nanoto Enabled - 3. Set
#optimization-guide-on-device-modelto Enabled ByPassPerfRequirement - 4. Restart Chrome and verify model status at
chrome://components