Code Block
Use the shorthand with code or tabs, or compose Header, List,
Actions, and Content yourself. Copy copies the raw source of the active tab.
Installation
Copy the command below and run it in your terminal.
The component depends on highlight.js. Install it if your project
doesn't have it yet:
Copy the command below and run it in your terminal.
Usage
Pass code and lang for one snippet, or a tabs array for several. Root's value picks the
open tab by matching each tab's value,
which defaults to its lang. It is
bindable and starts on the first tab.
The default theme colors tokens with GitHub light and GitHub dark, and theme presets set
their own palette. To use a highlight.js theme instead, set theme="custom" and load its stylesheet. The component then skips its own token colors.
Examples
Single snippet
Multiple languages
Line numbers
Custom actions
Copy placement: overlay
Copy placement: inline
Compound API
Custom theme: stylesheet
With theme="custom" the block paints no token colors itself, so a stock highlight.js stylesheet or your own hljs-* rules take over. This example uses One Dark and One Light rules.
export async function getUser(id: string) {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error('Not found');
return res.json();
}Custom theme: variables
To recolor tokens without a stylesheet, set the nine --code-block-token-* variables on a wrapper, then set them again under .dark for dark mode.
Anatomy
CodeBlock.Root - Provides code block state and layout.
CodeBlock.Header - Renders the code block header.
CodeBlock.List - Groups code language tabs.
CodeBlock.Trigger - Selects a code language tab.
CodeBlock.Actions - Groups code block actions.
CodeBlock.Copy - Copies the active code snippet.
CodeBlock.Content - Renders a code snippet panel.
CodeBlock - Renders a high-level code block.
# Import the Pinecone library from pinecone import Pinecone # Initialize a Pinecone client with your API key pc = Pinecone(api_key="YOUR_API_KEY") # Create an index for dense vectors with integrated embedding index_name = "quickstart-py" pc.create_index_for_model( name=index_name, cloud="aws", region="us-east-1", embed={ "model": "llama-text-embed-v2", "field_map": {"text": "chunk_text"}, }, )