Documentation
Components
MarkdownRenderer

MarkdownRenderer Component

The MarkdownRenderer component safely renders markdown content with syntax highlighting and custom element support.

Import

import { MarkdownRenderer } from 'aichatkit'

Usage

Basic Example

basic-markdown-renderer.tsx
import { MarkdownRenderer } from 'aichatkit'
 
function BasicMarkdownRenderer() {
  const content = `
# Hello World
 
This is **bold** and *italic* text.
 
\`\`\`javascript
console.log('Hello, world!')
\`\`\`
  `
 
  return <MarkdownRenderer content={content} />
}

With Custom Components

custom-markdown-renderer.tsx
<MarkdownRenderer 
  content={content}
  components={{
    code: CustomCodeBlock,
    link: CustomLink,
    image: CustomImage
  }}
  enableSyntaxHighlighting={true}
/>

API Reference

Props

PropTypeDefaultDescription
contentstring-Markdown content to render
componentsobject{}Custom component overrides
enableSyntaxHighlightingbooleantrueEnable code syntax highlighting
allowDangerousHtmlbooleanfalseAllow raw HTML rendering
linkTargetstring'_blank'Target for external links
classNamestring-Additional CSS classes

Custom Components

Code Block Override

const CustomCodeBlock = ({ children, className }) => (
  <pre className={`custom-code ${className}`}>
    <code>{children}</code>
  </pre>
)

Link Override

const CustomLink = ({ href, children }) => (
  <a href={href} className="custom-link" target="_blank">
    {children}
  </a>
)
⚠️

Be cautious when enabling allowDangerousHtml as it can introduce security vulnerabilities.