2.10.0
中文
Skip to content

CodeHighlighter ​

Highlight formatted code. Aligned with React @ant-design/x CodeHighlighter.

Standalone component. The Markdown plugin HighlightCode is still available; the two serve different purposes (plugin ≠ this component).

中文:CodeHighlighter 代码高亮

When to use ​

  • Show syntax-highlighted snippets with copy and header language info.
  • Combine with XMarkdown via components.code to render fenced code blocks.

Examples ​

Basic ​

JavaScript Code

javascript
import { ref } from 'vue';
import { Button } from 'ant-design-vue';

const App = () => (
  <div>
    <Button type="primary">Primary Button</Button>
  </div>
);

export default App;

CSS Code

css
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

HTML Code

html
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
</head>
<body>
  <h1>Hello World</h1>
</body>
</html>

Prism Light Mode

使用 prismLightMode 按需加载语言,减小打包体积。

javascript
import { ref } from 'vue';
import { Button } from 'ant-design-vue';

const App = () => (
  <div>
    <Button type="primary">Primary Button</Button>
  </div>
);

export default App;
Basic

Basic usage with on-demand language loading (prismLightMode).

Custom header ​

Vue 计数器示例
JavaScript
import { ref } from 'vue';

function useCounter() {
  const count = ref(0);
  const inc = () => {
    count.value += 1;
  };
  return { count, inc };
}
Custom header

Customize the header with header. Pass false / null to hide it.

With XMarkdown ​

With XMarkdown

Use it as components.code inside Bubble + XMarkdown.

API ​

CodeHighlighterProps ​

PropDescriptionTypeDefaultVersion
langLanguage idstring--
childrenCode content (or default slot)string--
headerHeader content; hidden when false / nullVNode | string | (() => VNode | string | false | null) | false | null--
highlightPropsExtra options for the highlighter (showLineNumbers / startingLineNumber / codeTagProps, …)CodeHighlighterHighlightProps--
prismLightModePrism light mode (lazy-load by lang)booleantrue-
classNamesSemantic class namesPartial\<Record\<SemanticType, string\>\>--
stylesSemantic stylesPartial\<Record\<SemanticType, CSSProperties\>\>--
prefixClsClass prefixstring--
rootClassNameExtra class on the rootstring--

Slots ​

SlotDescription
defaultCode content (string)
headerCustom header

CodeHighlighter Ref ​

PropDescriptionType
nativeElementNative DOM nodeHTMLElement

SemanticType ​

NameDescription
rootRoot
headerHeader container
headerTitleTitle
codeCode container

Semantic DOM ​

typescript
import { XMarkdown } from '@ant-design-x-vue/x-markdown';

const App = () => <XMarkdown content='Hello World' />;
export default App;
  • root
    根节点
  • header
    头部的容器
  • headerTitle
    标题
  • code
    代码容器

Design Token ​

TokenDescriptionDefault
colorBgTitleTitle backgroundcolorFillContent
colorTextTitleTitle textcolorText
colorBorderCodeCode block bordercolorBorderSecondary

Contributors ​

Contributors

Loading contributors…