Skip to content

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:

bash
pnpm add shiki
bash
npm install shiki
bash
yarn add shiki

If shiki is not installed, the component falls back to a plain <pre><code> block.

Basic usage ​

ts

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.

bash

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).

vue

Custom theme ​

Override the auto-detected theme with any shiki built-in theme.

js

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.

ts

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.

bash

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).

ts

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:

ts

For app-wide translations, set up the maz-ui translations plugin and the component will pick up your locale automatically.

Props ​

NameDescriptionTypeRequiredDefault
codeSource code to highlightstringNoundefined
languageLanguage identifier for syntax highlighting (e.g. 'vue', 'ts', 'bash')stringNoundefined
themeOverride the shiki theme name. Defaults to github-light/github-dark based on current color modestringNoundefined
roundedApply rounded corners on the highlighted code block.booleanNotrue
copyableShow the copy-to-clipboard button on hover.booleanNotrue
copy-valueValue 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).stringNoundefined
translationsCustom translations for the component. Override either key independently.Partial<MazUiTranslationsNestedSchema['codeHighlight']>Noundefined