CodeHighlighterCode Highlighting
CodeHighlighter
Code Highlighting
Used to highlight code formatting.
Importimport { CodeHighlighter } from "@ant-design/x"; |
Docs |
Importimport { CodeHighlighter } from "@ant-design/x"; |
Docs |
The CodeHighlighter component is used in scenarios where you need to display code snippets with syntax highlighting.
For common properties, refer to: Common Properties.
| Property | Description | Type | Default |
|---|---|---|---|
| lang | Language | string | - |
| children | Code content | string | - |
| header | Header | React.ReactNode | null | React.ReactNode |
| className | Style class name | string | |
| classNames | Style class names | string | - |
| highlightProps | Code highlighting configuration | highlightProps | - |
| Property | Description | Type | Version |
|---|---|---|---|
| nativeElement | Get native element | HTMLElement | - |
| Token Name | Description | Type | Default Value |
|---|---|---|---|
| colorBgTitle | Title background color | string | rgba(0,0,0,0.06) |
| colorBorderCode | Code block border color | string | #f0f0f0 |
| colorTextTitle | Title text color | string | rgba(0,0,0,0.88) |
import React from 'react';
import { Button } from 'antd';
const App = () => (
<div>
<Button type="primary">Primary Button</Button>
</div>
);
export default App;.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>当前计数:{count}</p>
<button onClick={() => setCount(count + 1)}>增加</button>
</div>
);
}import React from 'react';
import { XMarkdown } from '@ant-design/x-markdown';
const App = () => <XMarkdown content='Hello World' />;
export default App;