MarkdownRenderer Component
TheMarkdownRenderer
component provides consistent markdown rendering across Cedar OS with advanced features like code syntax highlighting, copy functionality, and prefix processing for chat interfaces.
Features
- GitHub Flavored Markdown: Full GFM support including tables, strikethrough, and more
- Code Highlighting: Syntax highlighting with copy-to-clipboard functionality
- Prefix Processing: Special handling for prefixed content (useful in chat)
- Cedar OS Integration: Automatic theming and styling consistency
- Inline/Block Modes: Flexible rendering for different contexts
- Interactive Elements: Copy buttons, hover effects, and edit placeholders
Import
Basic Usage
Props
Prop | Type | Default | Description |
---|---|---|---|
content | string | - | The markdown content to render (required) |
processPrefix | boolean | false | Whether to process prefix markers for special styling |
className | string | '' | Additional CSS classes |
inline | boolean | false | Whether to render in inline mode |
Supported Markdown Elements
Headers
Text Formatting
Links
- Opens in new tab automatically
noopener noreferrer
for security
Code Blocks
- Language detection and display
- Copy to clipboard button
- Edit placeholder button
- Syntax highlighting
- Horizontal scrolling for long lines
Lists
Blockquotes
Tables
Inline Mode
Perfect for rendering markdown within text flows:- Paragraphs render as
<span>
instead of<p>
- Maintains text flow
- Preserves inline formatting
Prefix Processing
For chat interfaces where you need special styling for prefixes:@@PREFIX@@
and @@ENDPREFIX@@
) are automatically:
- Styled with the accent color
- Processed recursively in nested elements
- Removed from final output
Code Block Features
Copy Functionality
- Hover over code blocks to see copy button
- Visual feedback when copied
- Automatic timeout after 2 seconds
Language Support
Inline Code
Styling Integration
The component automatically integrates with Cedar OS theming:Advanced Examples
Chat Message Rendering
Documentation Content
Inline Rich Text
Accessibility
- Proper semantic HTML structure
- Keyboard navigation support
- Screen reader friendly
- High contrast code blocks
- Focus indicators on interactive elements
Performance
- Efficient re-rendering with React.memo patterns
- Lazy loading for complex content
- Optimized regex processing
- Minimal DOM updates
Browser Support
- Modern browsers with ES6+ support
- Clipboard API for copy functionality
- CSS Grid/Flexbox for layout
- Graceful degradation for older browsers
Integration Notes
- Works seamlessly with TypewriterText component
- Consistent with other Cedar OS components
- Supports dark/light theme switching
- Responsive design for all screen sizes