Skip to content

AiCodeBlock

An intelligent code snippet component supporting syntax highlighting, clipboard integration, line numbers, and interactive expansions.

Basic Usage

Display code snippets with filename labels and a one-click copy feature.

main.ts
function greeting() {
console.log('Hello World!');
}
Basic Usage

Line Numbers & Highlighting

Enable line numbers with show-line-numbers and highlight specific lines using highlight-lines for better explanations.

advanced.ts
1234
function sum(a, b) {
// These lines will be highlighted
return a + b;
}
Line Numbers & Highlighting

Interaction & Collapsible

Supports collapsible states (collapsible) and a built-in run action (show-run).

script.js
console.log('Running AI simulation...');
Interaction & Collapsible

API

Props

Prop NameDescriptionTypeDefault
codeCode content stringstring''
filenameFilename to display in headerstring''
languageProgramming language identifierstring'text'
show-line-numbersWhether to show line numbersbooleanfalse
highlight-linesList of line numbers to highlightnumber[][]
collapsibleEnable collapsible featurebooleanfalse
default-collapsedInitial collapsed statebooleanfalse
show-runWhether to show the run buttonbooleanfalse
highlightEnable syntax highlightingbooleantrue
theme-overridesComponent-level theme overridesComponentThemeVars

Events

Event NameDescriptionCallback Parameters
copyTriggered when code is copied(code: string) => void
runTriggered when the run button is clicked(code: string) => void

Slots

Slot NameDescription
defaultCustom internal content
actionsInject custom interactive buttons in the toolbar

Use in Nuxt

Functions smoothly within Vue SSR and Nuxt Server-Side environments combining highlight.js natively. Please inspect Nuxt Usage to unleash seamless isomorphic builds.

SSR Notes:

  • ✅ Pure static strings generation safely rendered
  • ✅ Smooth hydration processes upon browser loads

SSR Safety

AiCodeBlock securely resolves AST structures inside virtual trees safely.

Theme Variables

Variable NameDescriptionDefault Value
--yh-ai-code-block-bgCode area background color#282c34
--yh-ai-code-block-header-bgHeader toolbar background color#21252b
--yh-ai-code-block-border-colorBorder color#181a1f
--yh-ai-code-block-colorCode text color#abb2bf
--yh-ai-code-block-lang-colorLanguage label text color#828997
--yh-ai-code-block-border-radiusCode block border radius8px
--yh-ai-code-block-shadowCode block shadow0 4px 12px rgba(0, 0, 0, 0.15)

Released under the MIT License.