Skip to content
Latestv1.0.63

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.

Basic Usage

Line Numbers & Highlighting ​

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

Line Numbers & Highlighting

Interaction & Collapsible ​

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

Interaction & Collapsible

Edit Function ​

Supports clicking the "Edit" button to open Monaco editor for code modification.

Edit Function

API ​

Props ​

Prop NameDescriptionTypeDefault
codeCode content stringstring''
filenamein headerstring Filename to display''
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
show-editWhether to show the edit buttonbooleanfalse
editableWhether the code is editablebooleanfalse
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
editTriggered when the edit button is clicked(code: string) => void
updateTriggered when code is saved(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.