12const greeting = 'Hello, world!' console.log(greeting)
1234```ts const greeting = 'Hello, world!' console.log(greeting) ```
key=value syntax. Bare words (without =) become the title.123export default defineConfig({ plugins: [holocron()], })
12345```ts vite.config.ts export default defineConfig({ plugins: [holocron()], }) ```
title="..." for titles with special characters:12345```ts title="src/vite.config.ts" export default defineConfig({ plugins: [holocron()], }) ```
lines=false:npm install @holocron.so/vite
123```bash lines=false npm install @holocron.so/vite ```
bleed=true (or bleed=both) to extend into both margins, or bleed=none (or bleed=false) to keep the block fully inside the content column:123456import { defineConfig } from 'vite' import { holocron } from '@holocron.so/vite' export default defineConfig({ plugins: [holocron()], })
1234```ts bleed=true import { defineConfig } from 'vite' ... ```
bleed meta accepts true/both, right (the fenced-block default), or false/none.highlight:123456import { defineConfig } from 'vite' import { holocron } from '@holocron.so/vite' export default defineConfig({ plugins: [holocron()], })
12345678```ts highlight="1,4-5" import { defineConfig } from 'vite' import { holocron } from '@holocron.so/vite' export default defineConfig({ plugins: [holocron()], }) ```
123456import { defineConfig } from 'vite' import { holocron } from '@holocron.so/vite' export default defineConfig({ plugins: [holocron()], })
1234```ts vite.config.ts highlight="3" bleed=true import { defineConfig } from 'vite' ... ```
CodeGroup component. The bare word after the language becomes the tab label:1npm install @holocron.so/vite
123456789101112131415<CodeGroup> ```bash npm npm install @holocron.so/vite ``` ```bash pnpm pnpm add @holocron.so/vite ``` ```bash yarn yarn add @holocron.so/vite ``` </CodeGroup>
`variable` renders as variable.@holocron.so/vite and you need to highlight code outside of MDX (for example in a custom React component), import the same bundle from the @holocron.so/vite/prism export instead of adding prismjs yourself. This way you don't ship a duplicate Prism bundle in your client output.123456789101112131415161718192021222324import { useEffect, useState } from 'react' export function Highlighted({ code, lang }: { code: string; lang: string }) { const [html, setHtml] = useState<string>() // Lazy-load so the ~891KB Prism bundle doesn't block first paint. useEffect(() => { let cancelled = false import('@holocron.so/vite/prism').then(({ Prism }) => { if (cancelled) return const grammar = Prism.languages[lang] if (!grammar) return setHtml(Prism.highlight(code, grammar, lang)) }) return () => { cancelled = true } }, [code, lang]) if (html) { return <code className={`language-${lang}`} dangerouslySetInnerHTML={{ __html: html }} /> } return <code className={`language-${lang}`}>{code}</code> }
| Condition | Resolves to | Behavior |
browser | full Prism bundle | real syntax highlighting |
ssr | no-op stub | returns text unchanged, highlighting runs on the client |
import() and render plain code as the fallback so SSR output and first paint stay unhighlighted, then upgrade once Prism loads.Prism.languages[lang] to check a grammar exists before calling Prism.highlight. Missing grammars return undefined, so guard against it and fall back to plain text.CodeBlock component from @holocron.so/vite/mdx. This is handy for rendering code outside of docs, for example in a dashboard or settings page.123456789101112import { CodeBlock } from '@holocron.so/vite/mdx' const CLI_EXAMPLES = `npx @holocron.so/cli build npx @holocron.so/cli dev` export function CliHelp() { return ( <CodeBlock lang='bash' showLineNumbers={false}> {CLI_EXAMPLES} </CodeBlock> ) }
CodeBlock lazy-loads the same vendored Prism bundle internally, so you get highlighting without shipping a duplicate prismjs. The children prop is the raw code string.bleed prop controls how far the block extends past its content column. The component defaults to no bleed, so it stays fully inside its parent, which is what you want in a dashboard, modal, or card. Opt into bleed only when you render inside the docs prose column:bleed value | Behavior |
'both' / true | extends into both left and right margins |
'right' | extends into the right margin only |
'none' / false | no bleed, stays fully inside its parent (default) |
| Prop | Type | Description |
children | string | The raw code to render. |
lang | string | Language id for Prism, defaults to jsx. |
showLineNumbers | boolean | Line numbers on the left, on by default. |
title | string | Filename or label shown above the block. |
highlight | string | Comma-separated lines/ranges to focus, e.g. "1-3,7". |
bleed | boolean | Extend into the page margins, off by default. |