Participate in the WeaveFox "AI Artist" contest to win SEE Conf tickets and thousands of prizes

logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Code Examples
  • Themes
  • Streaming
    • Syntax Processing
    • Animation Effects
  • Components
    • Overview
    • Sources
    • Think
    • DataChart
    • Custom Component
  • Plugins
    • Overview
    • Latex
    • HighlightCode
    • Mermaid
    • CustomPlugins
    • Theme & Locale

Code Examples

When to Use

Used for rendering streaming Markdown format returned by LLM.

Code Examples

API

PropertyDescriptionTypeDefault
contentMarkdown content to renderstring-
childrenMarkdown content, alias for content propstring-
componentsCustom React components to replace HTML elementsRecord<string, React.ComponentType<ComponentProps> | keyof JSX.IntrinsicElements>, see details-
paragraphTagCustom HTML tag for paragraph elements to prevent validation errors when custom components contain block-level elementskeyof JSX.IntrinsicElements'p'
streamingConfiguration for streaming rendering behaviorStreamingOption, see syntax processing and animation effects-
configMarked.js configuration for Markdown parsing and extensionsMarkedExtension{ gfm: true }
openLinksInNewTabWhether to add target="_blank" to all a tagsbooleanfalse
dompurifyConfigDOMPurify configuration for HTML sanitization and XSS protectionDOMPurify.Config-
classNameAdditional CSS class for root containerstring-
rootClassNameAlias for className, additional CSS class for root elementstring-
styleInline styles for root containerCSSProperties-

StreamingOption

PropertyDescriptionTypeDefault
hasNextChunkIndicates whether there are subsequent content chunks. When false, flushes all caches and completes renderingbooleanfalse
enableAnimationEnables text fade-in animation for block-level elements (p, li, h1, h2, h3, h4)booleanfalse
animationConfigConfiguration for text appearance animation effectsAnimationConfig{ fadeDuration: 200, opacity: 0.2 }
incompleteMarkdownComponentMapCustom component names for incomplete syntax. When streaming output contains unclosed Markdown syntax (e.g., incomplete tables, unterminated code blocks), you can manually specify the component name to wrap the fragment for placeholder or loading states.{ link?: string; image?: string; table?: string; html?: string }{}

AnimationConfig

PropertyDescriptionTypeDefault
fadeDurationDuration of fade-in animation in millisecondsnumber200
opacityInitial opacity value for characters during animation (0-1)number0.2

ComponentProps

PropertyDescriptionTypeDefault
domNodeComponent DOM node from html-react-parser, containing parsed DOM node informationDOMNode-
streamStatusStreaming rendering supports two states: loading indicates content is being loaded, done indicates loading is complete. Currently only supports HTML format and fenced code blocks. Since indented code blocks have no explicit terminator, they always return done status'loading' | 'done'-
restComponent props, supports all standard HTML attributes (e.g., href, title, className) and custom data attributesRecord<string, any>-

FAQ

Difference Between Components and Config Marked Extensions

Config Marked Extensions (Plugin Extensions)

The extensions in the config property are used to extend the functionality of the Markdown parser, they take effect during the Markdown to HTML conversion process:

  • Stage: Markdown parsing stage
  • Function: Recognize and convert special Markdown syntax
  • Example: Convert [^1] footnote syntax to <footnote>1</footnote> HTML tag
  • Use Case: Extend Markdown syntax to support more markup formats
typescript
// Plugin example: footnote extension
const footnoteExtension = {
name: 'footnote',
level: 'inline',
start(src) { return src.match(/\[\^/)?.index; },
tokenizer(src) {
const rule = /^\[\^([^\]]+)\]/;
const match = rule.exec(src);
if (match) {
return {
type: 'footnote',
raw: match[0],
text: match[1]
};
}
},
renderer(token) {
return `<footnote>${token.text}</footnote>`;
}
};
// Using the plugin
<XMarkdown
content="This is a footnote example[^1]"
config={{ extensions: [footnoteExtension] }}
/>

Components (Component Replacement)

The components property is used to replace generated HTML tags with custom React components:

  • Stage: HTML rendering stage
  • Function: Replace HTML tags with React components
  • Example: Replace <footnote>1</footnote> with <CustomFootnote>1</CustomFootnote>
  • Use Case: Customize rendering styles and interactive behavior of tags
typescript
// Custom footnote component
const CustomFootnote = ({ children, ...props }) => (
<sup
className="footnote-ref"
onClick={() => console.log('Clicked footnote:', children)}
style={{ color: 'blue', cursor: 'pointer' }}
>
{children}
</sup>
);
// Using component replacement
<XMarkdown
content="<footnote>1</footnote>"
components={{ footnote: CustomFootnote }}
/>

Incomplete Syntax Token Conversion

When hasNextChunk is true, all incomplete syntax tokens are automatically converted to incomplete-token form, and the incomplete syntax is returned via the data-raw property. The supported token type is StreamCacheTokenType. For example:

  • Incomplete link [example](https://example.com will be converted to <incomplete-link data-raw="[example](https://example.com">
  • Incomplete image ![product](https://cdn.example.com/images/produc will be converted to <incomplete-image data-raw="![product](https://cdn.example.com/images/produc">
  • Incomplete heading ### will be converted to <incomplete-heading data-raw="###">

StreamCacheTokenType Type

StreamCacheTokenType is an enumeration type that defines all Markdown syntax token types supported during streaming processing:

typescript
type StreamCacheTokenType =
| 'text' // Plain text
| 'link' // Link syntax [text](url)
| 'image' // Image syntax ![alt](src)
| 'heading' // Heading syntax # ## ###
| 'emphasis' // Emphasis syntax *italic* **bold**
| 'list' // List syntax - + *
| 'table' // Table syntax | header | content |
| 'xml'; // XML/HTML tags <tag>
Basic Usage

Basic markdown syntax rendering.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Streaming Processing

Incomplete syntax handling and animation effects

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Plugin Usage

Rendering with plugins.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Components

Custom component rendering tags.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Extension Plugin

Render custom markers [^1].

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Tokens

Use tokenizer make % as heading rendering.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Token Processing

Use walkTokens to check link validity and modify tokens.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Pre-rendering Processing

Use renderer to perform pre-rendering effect processing and render HTML as text, while adding 🚀 before each heading.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Chinese Link Handling

Link processing for English and Chinese content. Supports internationalized display with both English and Chinese text content, demonstrating markdown link parsing and rendering capabilities.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
XSS Defense
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Open Links in New Tab

Open links in new tab.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
动画
语法处理

启用新标签页打开链接

禁用新标签页打开链接(默认)