MazCodeHighlight
MazCodeHighlight displays source code with syntax highlighting powered by shiki. It auto-detects dark/light mode, ships with a copy-to-clipboard button, a language badge, and supports lazy loading.
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
Installation requirement
Install shiki in your project to enable highlighting:
pnpm add shikinpm install shikiyarn add shikiIf shiki is not installed, the component falls back to a plain <pre><code> block.
Basic usage
With slot
The default slot text is used as source code when the code prop is not provided. This is useful for plain text blocks.
Languages
Pass any valid shiki language identifier to the language prop. The chosen language is also displayed as a small badge in the top-right corner (the badge fades out on hover when the copy button appears).
Custom theme
Override the auto-detected theme with any shiki built-in theme.
Copy to clipboard
A copy button is displayed in the top-right corner on hover (or when focused via keyboard). Clicking it writes the resolved code to the clipboard and shows a check icon for ~1.5s.
Disable the copy button
Set :copyable="false" to hide the button entirely.
Copy a different value than the displayed code
Use copyValue when the displayed source differs from what should be copied — for example to strip a leading $ prompt when rendering a shell command. This is the mechanism MazWindowMockup uses internally to keep the terminal prompt out of the clipboard.
Disable rounded corners
Set :rounded="false" to render the highlighted block with squared corners — useful when embedding inside another container that already has its own border-radius (e.g. inside MazWindowMockup).
Custom translations
The copy button's aria-label and tooltip come from the @maz-ui/translations package (codeHighlight.copyToClipboard / codeHighlight.copiedToClipboard). You can override either key per-instance with the translations prop without touching the global locale:
For app-wide translations, set up the maz-ui translations plugin and the component will pick up your locale automatically.
Props
| Name | Description | Type | Required | Default |
|---|---|---|---|---|
| code | Source code to highlight | string | No | undefined |
| language | Language identifier for syntax highlighting (e.g. 'vue', 'ts', 'bash') | string | No | undefined |
| theme | Override the shiki theme name. Defaults to github-light/github-dark based on current color mode | string | No | undefined |
| rounded | Apply rounded corners on the highlighted code block. | boolean | No | true |
| copyable | Show the copy-to-clipboard button on hover. | boolean | No | true |
| copy-value | Value copied to the clipboard. Falls back to the resolved code when omitted. Useful when the displayed code differs from what should be copied (e.g. terminal prompt prefix). | string | No | undefined |
| translations | Custom translations for the component. Override either key independently. | Partial<MazUiTranslationsNestedSchema['codeHighlight']> | No | undefined |