logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Code Examples
  • Themes
  • Streaming
    • Syntax Processing
    • Animation Effects
  • Components
    • Overview
    • 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 LLMs.

Code Demos

API

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

SteamingOption

PropertyDescriptionTypeDefault
hasNextChunkIndicates whether more content chunks are expected. When false, flushes all cached content and completes renderingbooleanfalse
enableAnimationEnables text fade-in animation for block elements (p, li, h1, h2, h3, h4)booleanfalse
animationConfigConfiguration for text appearance animation effectsAnimationConfig{ fadeDuration: 200, easing: 'ease-in-out' }
incompletePlaceholderMapPlaceholder mapping for unclosed Markdown elements, supports custom placeholder components for links and images{ link?: string; image?: string }{ link: 'incomplete-link', image: 'incomplete-image' }

AnimationConfig

PropertyDescriptionTypeDefault
fadeDurationDuration of the fade-in animation in millisecondsnumber200
easingEasing function for the animationstring'ease-in-out'

ComponentProps

PropertyDescriptionTypeDefault
domNodeComponent Element from html-react-parser, contains the parsed DOM node informationDOMNode-
streamStatusStreaming status, loading indicates streaming in progress, done indicates streaming complete'loading' | 'done'-
restComponent properties, supports all standard HTML attributes (e.g. href, title, className, etc.) 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, acting 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 tags
  • 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 tag rendering styles and interactive behavior
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 }}
/>
Basic Usage

Basic Markdown syntax rendering.

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

Streaming conversation with Bubble.

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
Plugin Usage

Rendering with plugins.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Extension Plugin
CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
XSS Protection
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

启用新标签页打开链接

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