API 文档Props 属性

Props 属性

DsMarkdown 和 MarkdownCMD 通用属性

属性类型说明默认值
intervalnumber | IntervalConfig打字间隔配置,支持固定间隔或动态速度控制30
timerType'setTimeout' | 'requestAnimationFrame'定时器类型,不支持动态修改'setTimeout'
answerTypeAnswerType内容类型(影响样式主题),不支持动态修改'answer'
themeTheme主题类型'light'
pluginsIMarkdownPlugin[]插件配置[]
mathIMarkdownMath数学公式配置{ splitSymbol: 'dollar' }
showCursorboolean打字动画时是否显示光标false
cursorReact.ReactNode | 'line' | 'block' | 'underline' | 'circle'自定义光标元素或内置光标类型'line' (当 showCursortrue 时)
onEnd(data?: IEndData) => void打字完成回调-
onStart(data?: IStartData) => void打字开始回调-
onBeforeTypedChar(data?: IBeforeTypedChar) => Promise<void>字符打字前的回调,支持异步操作,会阻塞之后的打字-
onTypedChar(data?: ITypedChar) => void每字符打字后的回调-
disableTypingboolean禁用打字动画效果false
autoStartTypingboolean是否自动开始打字动画,设为 false 时需手动触发,不支持动态修改true
codeBlockIMarkdownCode代码块配置{headerActions: true}
experimentalIncrementalRenderboolean实验性 增量渲染模式。开启后避免每次打字时全量重新解析 Markdown,提升长内容场景下的性能false
incrementalFlushThresholdnumber增量模式下的尾部大小阈值,用于决定何时刷新。仅在 experimentalIncrementalRender 开启时有效-

DsMarkdown 特有属性

属性类型说明默认值
childrenstring | undefinedMarkdown 内容-

MarkdownCMD 特有属性

MarkdownCMD 不需要 children 属性,内容通过 push() 方法动态添加。

使用示例

基础配置

<DsMarkdown 
  interval={20}
  theme="dark"
  answerType="answer"
  showCursor
  cursor="block"
>
  # 内容
</DsMarkdown>

动态速度控制

<DsMarkdown 
  interval={{
    min: 10,
    max: 50,
    curve: 'ease-out'
  }}
>
  内容...
</DsMarkdown>

回调函数

<DsMarkdown
  onStart={(data) => console.log('开始', data)}
  onEnd={(data) => console.log('完成', data)}
  onTypedChar={(data) => console.log('打字', data)}
>
  内容...
</DsMarkdown>