2.10.0
中文
Skip to content

XMarkdown plugins ​

Plug-ins are divided into two categories. Objects with transform(content) in plugins will rewrite the Markdown string before parsing. Formulas, highlighting, and Mermaid use the marked extension or components mapping, just like React @ant-design/x-markdown@2.10.0.

Publish the subpath in the package:

  • @ant-design-x-vue/x-markdown/plugins/Latex
  • @ant-design-x-vue/x-markdown/plugins/HighlightCode
  • @ant-design-x-vue/x-markdown/plugins/Mermaid

The main entrance also exports these three names. The browser script package does not have a separate copy of dist/plugins/*.min.js, please use the package entry or subpath.

String transform ​

plugin

Ship the TODO before Friday.

String transform

The transform of plugins runs before marked.

Latex ​

Latex(options?) returns marked extensions, which are passed to config.extensions. By default, align* is replaced with aligned. katexOptions are passed directly to KaTeX.

PropDescriptionTypeDefault
replaceAlignStartWhether to replace align* with alignedbooleantrue
katexOptionsKaTeX configurationKatexOptions{ output: 'html', throwOnError: false }

Pythagoras: .

Inline $...$ and block $$.

Progressively parse formulas while they stream.

Standalone page: Formulas.

HighlightCode ​

Fenced code is rendered as <code class="language-*">. The class is read via components.code and then passed to HighlightCode. Inline code remains as standard <code>.

PropDescriptionTypeDefault
langLanguage namestring-
childrenCode textstring-
headerTop bar; if null, the default top bar is not renderedVNode | nullDefault top bar
classNameRoot class namestring-
classNamesroot / header / headerTitle / codeobject-
stylesInline styles corresponding to classNamesobject-

A fenced block picks up the language class:

ts
export const answer = 42;

Inline const x = 1 stays a plain code tag.

Fenced code goes through HighlightCode.

Progressively highlight a streaming code block.

Standalone page: Highlighted Code.

Mermaid ​

components.code is replaced by Mermaid when the language is mermaid. The chart library is only initialized in the browser, and server-side rendering displays the source code first.

PropDescriptionTypeDefault
childrenChart source codestring-
headerTop bar; do not render the default toolbar when nullVNode | nullDefault toolbar
classNameRoot class namestring-
classNamesroot / header / graph / codeobject-
stylesInline styles corresponding to classNamesobject-
```mermaid
graph TD
  A[Start] --> B[Answer]
```

A flowchart.

Here are several Mermaid diagram examples

#### 1. Flowchart (Vertical)

``` mermaid
graph TD
    A[Start] --> B{Data Valid?}
    B -->|Yes| C[Process Data]
    B -->|No| D[Error Handling]
    C --> E[Generate Report]
    D --> E
    E --> F[End]
    style A fill:#2ecc71,stroke:#27ae60
    style F fill:#e74c3c,stroke:#c0392b
```

#### 2. Sequence Diagram

``` mermaid
sequenceDiagram
    participant Client
    participant Server
    participant Database

    Client->>Server: POST /api/data
    Server->>Database: INSERT record
    Database-->>Server: Success
    Server-->>Client: 201 Created
```

#### 3. Quadrant Chart

```mermaid
quadrantChart
    title Reach and engagement of campaigns
    x-axis Low Reach --> High Reach
    y-axis Low Engagement --> High Engagement
    quadrant-1 We should expand
    quadrant-2 Need to promote
    quadrant-3 Re-evaluate
    quadrant-4 May be improved
    Campaign A: [0.3, 0.6]
    Campaign B: [0.45, 0.23]
    Campaign C: [0.57, 0.69]
    Campaign D: [0.78, 0.34]
    Campaign E: [0.40, 0.34]
    Campaign F: [0.35, 0.78]
```

Progressively render a streaming Mermaid fence.

Independent page: Mermaid · GPT-VIS.

Think ​

Custom labels can be mapped to dialog components. think is handed over to Think, the default slot is the text in the label. Sources / ThoughtChain use the same components notation, see Chat Enhancement.

Check the constraint, then answer.

The answer is 42.

Render think tags as Think.

Theme and copy ​

The button text of HighlightCode and Mermaid comes from useLocale. Use XProvider to wrap it up and replace it. Styles are available in the components styles / classNames, or follow the ant-design-vue Design Token. See Theme and Copy for details. For the Markdown text theme class name, see theme.

Custom plugin ​

Supports marked extensions or custom plug-ins with transform, see custom plug-in.