Syntax Processing
The syntax processing mechanism is specifically designed for streaming rendering scenarios. It can intelligently identify incomplete Markdown syntax structures and provide a smooth user experience through flexible custom component mapping.
| Parameter | Description | Type | Default Value |
|---|---|---|---|
| hasNextChunk | Whether there is subsequent data | boolean | false |
| enableAnimation | Enable text fade-in animation | boolean | false |
| animationConfig | Text animation configuration | AnimationConfig | { fadeDuration: 200, easing: 'ease-in-out' } |
| incompleteMarkdownComponentMap | Custom component names for incomplete syntax. When streaming output contains unclosed Markdown syntax (such as half-finished tables or unterminated code blocks), you can manually specify the component name to wrap the fragment for placeholder or loading states. | Partial<Record<Exclude<StreamCacheTokenType, 'text'>, string>> | {} |
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:
[Example](https://example.com will be converted to <incomplete-link data-raw="[Example](https://example.com">| 'image' // Image syntax | 'heading' // Heading syntax # ## ###| 'emphasis' // Emphasis syntax *italic* **bold**| 'list' // List syntax - + *| 'table' // Table syntax | header | content || 'xml'; // XML/HTML tags <tag>
Streaming syntax processing supports integrity checks for the following Markdown syntax:
| Syntax Type | Format Example | Processing Mechanism | Incomplete State Example | Corresponding TokenType |
|---|---|---|---|---|
| Link | [text](url) | Detect unclosed link markers | [Example Website](https://example | link |
| Image |  | Detect unclosed image markers |  => <Skeleton.Image active style={{ width: 60, height: 60 }} />;const IncompleteLink = (props: ComponentProps) => {const text = String(props['data-raw'] || '');// Extract link text, format is [text](url)const linkTextMatch = text.match(/^\[([^\]]*)\]/);const displayText = linkTextMatch ? linkTextMatch[1] : text.slice(1);return (<a style={{ pointerEvents: 'none' }} href="#">{displayText}</a>);};const App = () => {return (<XMarkdowncontent="Visit [Ant Design](https://ant.design) for documentation, there are `code examples` and |table data|"streaming={{hasNextChunk,incompleteMarkdownComponentMap: {link: 'link-loading',},}}components={{'link-loading': ImageSkeleton,'incomplete-link': IncompleteLink,}}/>);};
During streaming transmission, Markdown syntax may be in an incomplete state:
// Incomplete link syntax: [Example Website](https://example // Incomplete image syntax: ![Product Image](https://cdn.example.com/images/produc
Incomplete syntax structures may cause:
hasNextChunk should not always be true, otherwise it would cause the following issues: