11# MarkdownRenderer Component
22
3- The ` MarkdownRenderer ` component provides consistent markdown rendering across Cedar OS with advanced features like code syntax highlighting, copy functionality, and prefix processing for chat interfaces .
3+ A markdown renderer powered by [ Streamdown ] ( https://github.com/vercel/streamdown ) for streaming AI content .
44
5- ## Features
6-
7- - ** GitHub Flavored Markdown** : Full GFM support including tables, strikethrough, and more
8- - ** Code Highlighting** : Syntax highlighting with copy-to-clipboard functionality
9- - ** Prefix Processing** : Special handling for prefixed content (useful in chat)
10- - ** Cedar OS Integration** : Automatic theming and styling consistency
11- - ** Inline/Block Modes** : Flexible rendering for different contexts
12- - ** Interactive Elements** : Copy buttons, hover effects, and edit placeholders
13-
14- ## Import
5+ ## Installation & Basic Usage
156
167``` tsx
178import { MarkdownRenderer } from ' cedar-os-components/chatMessages/MarkdownRenderer' ;
18- ```
199
20- ## Basic Usage
21-
22- ``` tsx
23- <MarkdownRenderer content = ' # Hello World\n\nThis is **bold** and *italic* text.' />
10+ <MarkdownRenderer content = ' # Hello World\n\nThis is **bold** text.' />;
2411```
2512
2613## Props
2714
28- | Prop | Type | Default | Description |
29- | --------------- | --------- | ------- | ----------------------------------------------------- |
30- | ` content ` | ` string ` | - | The markdown content to render (required) |
31- | ` processPrefix ` | ` boolean ` | ` false ` | Whether to process prefix markers for special styling |
32- | ` className ` | ` string ` | ` '' ` | Additional CSS classes |
33- | ` inline ` | ` boolean ` | ` false ` | Whether to render in inline mode |
34-
35- ## Supported Markdown Elements
36-
37- ### Headers
38-
39- ``` markdown
40- # H1 Header
41-
42- ## H2 Header
43-
44- ### H3 Header
45-
46- #### H4 Header
47-
48- ##### H5 Header
49-
50- ###### H6 Header
51- ```
52-
53- ### Text Formatting
54-
55- ``` markdown
56- ** Bold text**
57- _ Italic text_
58- ~~ Strikethrough~~
59- ` Inline code `
60- ```
61-
62- ### Links
63-
64- ``` markdown
65- [ Link text] ( https://example.com )
66- ```
67-
68- - Opens in new tab automatically
69- - ` noopener noreferrer ` for security
70-
71- ### Code Blocks
72-
73- ```` markdown
74- ``` javascript
75- function hello () {
76- console .log (' Hello World!' );
77- }
78- ```
79- ````
80-
81- Features:
82-
83- - Language detection and display
84- - Copy to clipboard button
85- - Edit placeholder button
86- - Syntax highlighting
87- - Horizontal scrolling for long lines
88-
89- ### Lists
90-
91- ``` markdown
92- - Unordered list item 1
93- - Unordered list item 2
94-
95- 1 . Ordered list item 1
96- 2 . Ordered list item 2
97- ```
98-
99- ### Blockquotes
100-
101- ``` markdown
102- > This is a blockquote
103- > It can span multiple lines
104- ```
105-
106- ### Tables
107-
108- ``` markdown
109- | Column 1 | Column 2 | Column 3 |
110- | -------- | -------- | -------- |
111- | Row 1 | Data | More |
112- | Row 2 | Data | More |
113- ```
114-
115- ## Inline Mode
116-
117- Perfect for rendering markdown within text flows:
118-
119- ``` tsx
120- <MarkdownRenderer content = ' This is **bold** text inline' inline = { true } />
121- ```
122-
123- In inline mode:
124-
125- - Paragraphs render as ` <span> ` instead of ` <p> `
126- - Maintains text flow
127- - Preserves inline formatting
15+ | Prop | Type | Default | Description |
16+ | --------------- | --------- | ------- | ------------------------------------------------ |
17+ | ` content ` | ` string ` | - | Markdown content to render (required) |
18+ | ` processPrefix ` | ` boolean ` | ` false ` | Enable @@PREFIX @@ processing for chat interfaces |
19+ | ` className ` | ` string ` | ` '' ` | CSS class |
20+ | ` inline ` | ` boolean ` | ` false ` | Inline rendering mode |
12821
12922## Prefix Processing
13023
@@ -137,92 +30,28 @@ For chat interfaces where you need special styling for prefixes:
13730/>
13831```
13932
140- The prefix markers (` @@PREFIX@@ ` and ` @@ENDPREFIX@@ ` ) are automatically:
141-
142- - Styled with the accent color
143- - Processed recursively in nested elements
144- - Removed from final output
145-
146- ## Code Block Features
147-
148- ### Copy Functionality
149-
150- - Hover over code blocks to see copy button
151- - Visual feedback when copied
152- - Automatic timeout after 2 seconds
33+ The prefix markers are styled with accent color and removed from final output.
15334
154- ### Language Support
35+ ## Streaming AI Example
15536
15637``` tsx
157- <MarkdownRenderer
158- content = { `
159- \`\`\` typescript
160- interface User {
161- name: string;
162- email: string;
38+ import { MarkdownRenderer } from ' cedar-os-components/chatMessages/MarkdownRenderer' ;
39+ import { useChat } from ' @ai-sdk/react' ;
40+
41+ export default function Chat() {
42+ const { messages } = useChat ();
43+
44+ return messages .map ((message ) => (
45+ <MarkdownRenderer
46+ key = { message .id }
47+ content = { message .content }
48+ processPrefix = { true }
49+ />
50+ ));
16351}
164- \`\`\`
165- ` }
166- />
167- ```
168-
169- ### Inline Code
170-
171- ``` tsx
172- <MarkdownRenderer content = ' Use the `useState` hook for state management.' />
17352```
17453
175- ## Styling Integration
176-
177- The component automatically integrates with Cedar OS theming:
178-
179- ``` tsx
180- // Uses current styling context
181- const { styling } = useStyling ();
182-
183- // Applied to:
184- // - Accent colors for borders and highlights
185- // - Text colors for consistency
186- // - Background colors for code blocks
187- // - Table styling and borders
188- ```
189-
190- ## Advanced Examples
191-
192- ### Chat Message Rendering
193-
194- ```` tsx
195- <MarkdownRenderer
196- content = " @@PREFIX@@System: @@ENDPREFIX@@**Task completed!** Here's your code:\n\n```javascript\nconsole.log('Done!');\n```"
197- processPrefix = { true }
198- className = ' chat-message'
199- />
200- ````
201-
202- ### Documentation Content
203-
204- ``` tsx
205- <MarkdownRenderer
206- content = { `
207- # API Documentation
208-
209- ## Overview
210- This API provides **powerful** functionality.
211-
212- ### Example Request
213- \`\`\` bash
214- curl -X POST https://api.example.com/data
215- \`\`\`
216-
217- | Parameter | Type | Description |
218- |-----------|------|-------------|
219- | \` name\` | string | User name |
220- | \` email\` | string | User email |
221- ` }
222- />
223- ```
224-
225- ### Inline Rich Text
54+ ## Inline Mode
22655
22756``` tsx
22857<p >
@@ -234,32 +63,3 @@ curl -X POST https://api.example.com/data
23463 to get started.
23564</p >
23665```
237-
238- ## Accessibility
239-
240- - Proper semantic HTML structure
241- - Keyboard navigation support
242- - Screen reader friendly
243- - High contrast code blocks
244- - Focus indicators on interactive elements
245-
246- ## Performance
247-
248- - Efficient re-rendering with React.memo patterns
249- - Lazy loading for complex content
250- - Optimized regex processing
251- - Minimal DOM updates
252-
253- ## Browser Support
254-
255- - Modern browsers with ES6+ support
256- - Clipboard API for copy functionality
257- - CSS Grid/Flexbox for layout
258- - Graceful degradation for older browsers
259-
260- ## Integration Notes
261-
262- - Works seamlessly with TypewriterText component
263- - Consistent with other Cedar OS components
264- - Supports dark/light theme switching
265- - Responsive design for all screen sizes
0 commit comments