2.10.0
中文
Skip to content

Highlight Code ​

The fence code is rendered into <code> with language-*, and then passed to HighlightCode using components.code. Inline code remains normal <code>.

Import from @ant-design-x-vue/x-markdown/plugins/HighlightCode (the main entrance also exports the same name).

Examples ​

A fenced block picks up the language class:

ts
export const answer = 42;

Inline const x = 1 stays a plain code tag.

Examples

Basic highlighting.

Streaming highlighting.

API ​

PropDescriptionTypeDefault
langLanguage namestring-
childrenCode textstring-
headertop bar. Passing in VNode is completely customized; if null is used, the default top bar will not be renderedVNode | nullDefault language name + copy button
classNameRoot class namestring-
classNamesSemantic class names: root / header / headerTitle / codePartial\<Record<'root' | 'header' | 'headerTitle' | 'code', string\>\>-
stylesSemantic styling, key identical to 'classNames'Partial\<Record<..., CSSProperties\>\>-
styleRoot inline styleCSSProperties-
prefixClsOverride class prefixstring-

The copy button copy comes from useLocale('HighlightCode'), which can be switched with the locale of XProvider, see Theme and Copywriting.

Properties and more examples are also in plugins · HighlightCode.