@ceed/ads 1.20.0 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
+ Markdown is a component that renders markdown-formatted text as styled React components. It supports GitHub Flavored Markdown (GFM) including bold, italic, strikethrough, links, code blocks, tables, task lists, blockquotes, and lists. Additionally, it provides custom features like accent color highlighting using `||text||` syntax, configurable typography levels, and text alignment options. Markdown is ideal for displaying user-generated content, documentation, comments, and any dynamic text that requires rich formatting.
6
+
5
7
  ```tsx
6
8
  <Markdown
7
9
  content="This is markdown with **bold text** and *italic text* and ||accent color||"
@@ -15,3 +17,833 @@
15
17
  | defaultLinkAction | — | — |
16
18
  | accentColor | — | — |
17
19
  | textAlign | — | — |
20
+
21
+ > ⚠️ **Usage Warning** ⚠️
22
+ >
23
+ > Consider these guidelines when using Markdown:
24
+ >
25
+ > - **Security**: Always sanitize user-generated markdown content to prevent XSS attacks
26
+ > - **Performance**: For very long documents, consider lazy loading or pagination
27
+ > - **Styling consistency**: Use `defaultLevel` to match your app's typography system
28
+ > - **Links**: Use `defaultLinkAction` to control how links open (new tab vs same tab)
29
+
30
+ ## Usage
31
+
32
+ ```tsx
33
+ import { Markdown } from '@ceed/ads';
34
+
35
+ function ArticleContent({ content }) {
36
+ return (
37
+ <Markdown
38
+ content={content}
39
+ defaultLevel="body-md"
40
+ defaultLinkAction="_blank"
41
+ />
42
+ );
43
+ }
44
+ ```
45
+
46
+ ## Examples
47
+
48
+ ### Playground
49
+
50
+ Interactive example with basic markdown formatting.
51
+
52
+ ```tsx
53
+ <Markdown
54
+ content="This is markdown with **bold text** and *italic text* and ||accent color||"
55
+ />
56
+ ```
57
+
58
+ ### Default Level
59
+
60
+ Control the base typography level for the content.
61
+
62
+ ```tsx
63
+ <Stack spacing={2}>
64
+ <Markdown {...args} defaultLevel="title-lg" />
65
+ <Markdown {...args} defaultLevel="title-md" />
66
+ <Markdown {...args} defaultLevel="title-sm" />
67
+ <Markdown {...args} defaultLevel="body-lg" />
68
+ <Markdown {...args} defaultLevel="body-md" />
69
+ <Markdown {...args} defaultLevel="body-sm" />
70
+ <Markdown {...args} defaultLevel="body-xs" />
71
+ </Stack>
72
+ ```
73
+
74
+ ### Text Alignment
75
+
76
+ Align text to left, center, or right.
77
+
78
+ ```tsx
79
+ <Markdown
80
+ content="Hi I'm **markdown**"
81
+ textAlign="center"
82
+ />
83
+ ```
84
+
85
+ ### Colors
86
+
87
+ Apply different color themes to the markdown content.
88
+
89
+ ```tsx
90
+ <div>
91
+ <Markdown {...args} color="primary" />
92
+ <Markdown {...args} color="danger" />
93
+ <Markdown {...args} color="neutral" />
94
+ <Markdown {...args} color="success" />
95
+ <Markdown {...args} color="warning" />
96
+ </div>
97
+ ```
98
+
99
+ ### Text Color
100
+
101
+ Use specific text colors from the theme palette.
102
+
103
+ ```tsx
104
+ <Stack>
105
+ <Markdown {...args} textColor="common.black" />
106
+ <Markdown {...args} textColor="danger.400" />
107
+ <Markdown {...args} textColor="primary.500" />
108
+ </Stack>
109
+ ```
110
+
111
+ ### Accent Color
112
+
113
+ Highlight text with custom accent color using `||text||` syntax.
114
+
115
+ ```tsx
116
+ <Stack spacing={2}>
117
+ <Markdown {...args} />
118
+ <Markdown {...args} fontWeight={600} />
119
+ </Stack>
120
+ ```
121
+
122
+ ### Bold Font Weight
123
+
124
+ Customize the weight of bold text.
125
+
126
+ ```tsx
127
+ <Stack spacing={2}>
128
+ <Typography fontWeight="normal">Normal:</Typography>
129
+ <Markdown {...args} />
130
+
131
+ <Typography fontWeight="sm">SM:</Typography>
132
+ <Markdown {...args} boldFontWeight="sm" />
133
+ <Typography fontWeight="md">MD:</Typography>
134
+ <Markdown {...args} boldFontWeight="md" />
135
+ <Typography fontWeight="lg">LG:</Typography>
136
+ <Markdown {...args} boldFontWeight="lg" />
137
+ <Typography fontWeight="xl">XL:</Typography>
138
+ <Markdown {...args} boldFontWeight="xl" />
139
+ </Stack>
140
+ ```
141
+
142
+ ### Strikethrough
143
+
144
+ GFM strikethrough support using `~text~` syntax.
145
+
146
+ ```tsx
147
+ <Markdown content="I am markdown with ~strikethrough~" />
148
+ ```
149
+
150
+ ### Tables
151
+
152
+ Full GFM table support with alignment options.
153
+
154
+ ```tsx
155
+ <Markdown
156
+ content={"\n| Feature | Status | Notes |\n|---------|--------|-------|\n| Tables | ✅ Supported | GFM tables work |\n| Alignment | ✅ Supported | Left, center, right |\n| Headers | ✅ Supported | Bold headers |\n\n| Left | Center | Right |\n|:-----|:------:|------:|\n| L1 | C1 | R1 |\n| L2 | C2 | R2 |\n"}
157
+ />
158
+ ```
159
+
160
+ ### Code Blocks
161
+
162
+ Inline code and fenced code blocks with syntax highlighting.
163
+
164
+ ````tsx
165
+ <Markdown
166
+ content={"\nHere is some `inline code` in a sentence.\n\n```javascript\n// Code block with syntax highlighting\nfunction hello() {\n console.log('Hello, World!');\n}\n```\n\n```typescript\ninterface User {\n name: string;\n age: number;\n}\n```\n"}
167
+ />
168
+ ````
169
+
170
+ ### Task Lists
171
+
172
+ Interactive task list checkboxes.
173
+
174
+ ```tsx
175
+ <Markdown
176
+ content={"\n## Task List\n\n- [x] Completed task\n- [x] Another completed task\n- [ ] Incomplete task\n- [ ] Another incomplete task\n\n### Nested Tasks\n\n- Parent item\n - [x] Child completed\n - [ ] Child incomplete\n"}
177
+ />
178
+ ```
179
+
180
+ ### Blockquotes
181
+
182
+ Styled blockquotes for quoted content.
183
+
184
+ ```tsx
185
+ <Markdown
186
+ content={"\n> This is a blockquote.\n> It can span multiple lines.\n\n> **Note:** Blockquotes can contain **bold** and *italic* text.\n\n> Nested content:\n> - List item 1\n> - List item 2\n"}
187
+ />
188
+ ```
189
+
190
+ ### Lists
191
+
192
+ Ordered and unordered lists with nesting support.
193
+
194
+ ```tsx
195
+ <Markdown
196
+ content={"\n## Unordered List\n\n- First item\n- Second item\n- Third item\n - Nested item 1\n - Nested item 2\n\n## Ordered List\n\n1. First item\n2. Second item\n3. Third item\n 1. Nested item 1\n 2. Nested item 2\n"}
197
+ />
198
+ ```
199
+
200
+ ### GFM Complete
201
+
202
+ Full demonstration of all GFM features.
203
+
204
+ ````tsx
205
+ <Markdown
206
+ content={"\n# GFM Complete Example\n\nThis example demonstrates all **GitHub Flavored Markdown** features.\n\n## Text Formatting\n\n- **Bold text** using `**text**`\n- *Italic text* using `*text*`\n- ~Strikethrough~ using `~text~`\n- `Inline code` using backticks\n- ||Accent color|| using `||text||`\n\n## Links and Images\n\n[Visit GitHub](https://github.com)\n\n## Blockquotes\n\n> This is a blockquote with **bold** and *italic* text.\n>\n> Multiple paragraphs are supported.\n\n## Code Blocks\n\n```typescript\nconst greeting: string = 'Hello, GFM!';\nconsole.log(greeting);\n```\n\n## Tables\n\n| Syntax | Description | Example |\n|--------|-------------|---------|\n| Bold | Makes text bold | **bold** |\n| Italic | Makes text italic | *italic* |\n| Code | Inline code | `code` |\n\n## Lists\n\n### Unordered\n- Item 1\n- Item 2\n- Item 3\n\n### Ordered\n1. First\n2. Second\n3. Third\n\n### Task List\n- [x] Completed task\n- [ ] Pending task\n\n---\n\n*End of GFM demonstration*\n"}
207
+ />
208
+ ````
209
+
210
+ ## When to Use
211
+
212
+ ### ✅ Good Use Cases
213
+
214
+ - **Documentation**: Rendering help docs, READMEs, or guides
215
+ - **User-generated content**: Comments, posts, or descriptions with formatting
216
+ - **Dynamic content**: Content from CMS or databases stored as markdown
217
+ - **Release notes**: Changelogs and update information
218
+ - **Email templates**: Preview email content written in markdown
219
+ - **Chat/messaging**: Rich text messages with formatting
220
+ - **Knowledge bases**: FAQ answers and support articles
221
+
222
+ ### ❌ When Not to Use
223
+
224
+ - **Simple text**: Use Typography for plain text without formatting
225
+ - **Complex layouts**: Use proper components instead of markdown tables for data
226
+ - **Interactive content**: Don't rely on markdown for forms or inputs
227
+ - **Critical UI text**: Use Typography for button labels, form labels, etc.
228
+ - **Structured data**: Use DataTable or custom components for tabular data
229
+
230
+ ## Common Use Cases
231
+
232
+ ### Article/Blog Content
233
+
234
+ ```tsx
235
+ function ArticlePage({ article }) {
236
+ return (
237
+ <Box sx={{ maxWidth: 700, mx: 'auto', py: 4 }}>
238
+ <Typography level="h1" sx={{ mb: 2 }}>
239
+ {article.title}
240
+ </Typography>
241
+ <Stack direction="row" gap={2} sx={{ mb: 3 }}>
242
+ <Typography level="body-sm" color="neutral">
243
+ By {article.author}
244
+ </Typography>
245
+ <Typography level="body-sm" color="neutral">
246
+ {article.date}
247
+ </Typography>
248
+ </Stack>
249
+ <Divider sx={{ mb: 3 }} />
250
+ <Markdown
251
+ content={article.body}
252
+ defaultLevel="body-md"
253
+ defaultLinkAction="_blank"
254
+ />
255
+ </Box>
256
+ );
257
+ }
258
+ ```
259
+
260
+ ### Comment with Formatting
261
+
262
+ ```tsx
263
+ function Comment({ comment }) {
264
+ return (
265
+ <Card variant="outlined">
266
+ <CardContent>
267
+ <Stack direction="row" gap={2} alignItems="center" sx={{ mb: 2 }}>
268
+ <Avatar src={comment.author.avatar} size="sm" />
269
+ <Box>
270
+ <Typography level="title-sm">{comment.author.name}</Typography>
271
+ <Typography level="body-xs" color="neutral">
272
+ {comment.createdAt}
273
+ </Typography>
274
+ </Box>
275
+ </Stack>
276
+ <Markdown
277
+ content={comment.body}
278
+ defaultLevel="body-sm"
279
+ />
280
+ </CardContent>
281
+ </Card>
282
+ );
283
+ }
284
+ ```
285
+
286
+ ### Release Notes
287
+
288
+ ```tsx
289
+ function ReleaseNotes({ version, notes }) {
290
+ return (
291
+ <Box>
292
+ <Typography level="h2" sx={{ mb: 2 }}>
293
+ Version {version}
294
+ </Typography>
295
+ <Markdown
296
+ content={notes}
297
+ defaultLevel="body-md"
298
+ accentColor="success.500"
299
+ />
300
+ </Box>
301
+ );
302
+ }
303
+
304
+ // Usage with markdown content
305
+ const releaseNotes = `
306
+ ## What's New
307
+
308
+ - **New Feature**: Added ||dark mode support||
309
+ - **Improvement**: Faster load times
310
+ - **Bug Fix**: Fixed login issue on mobile
311
+
312
+ ### Breaking Changes
313
+
314
+ ~Old API endpoints are deprecated~. Please migrate to the new v2 endpoints.
315
+
316
+ ### Migration Guide
317
+
318
+ 1. Update your API calls
319
+ 2. Test thoroughly
320
+ 3. Deploy changes
321
+ `;
322
+ ```
323
+
324
+ ### Help Documentation
325
+
326
+ ```tsx
327
+ function HelpArticle({ title, content }) {
328
+ return (
329
+ <Container maxWidth="laptop">
330
+ <Typography level="h1" sx={{ mb: 3 }}>
331
+ {title}
332
+ </Typography>
333
+ <Markdown
334
+ content={content}
335
+ defaultLevel="body-md"
336
+ defaultLinkAction="_blank"
337
+ />
338
+ </Container>
339
+ );
340
+ }
341
+
342
+ // Example help content
343
+ const helpContent = `
344
+ ## Getting Started
345
+
346
+ Welcome to our platform! Here's how to get started:
347
+
348
+ ### Step 1: Create an Account
349
+
350
+ Visit the [signup page](/signup) and fill in your details.
351
+
352
+ > **Tip:** Use a strong password with at least 12 characters.
353
+
354
+ ### Step 2: Verify Your Email
355
+
356
+ Check your inbox for a verification email and click the link.
357
+
358
+ ### Step 3: Complete Your Profile
359
+
360
+ Add your profile information:
361
+
362
+ - [ ] Upload a profile picture
363
+ - [ ] Add your bio
364
+ - [ ] Set your preferences
365
+
366
+ ### Need Help?
367
+
368
+ Contact us at [support@example.com](mailto:support@example.com).
369
+ `;
370
+ ```
371
+
372
+ ### Task Description with Checklist
373
+
374
+ ```tsx
375
+ function TaskDetails({ task }) {
376
+ return (
377
+ <Card>
378
+ <CardContent>
379
+ <Typography level="title-lg" sx={{ mb: 2 }}>
380
+ {task.title}
381
+ </Typography>
382
+ <Markdown
383
+ content={task.description}
384
+ defaultLevel="body-sm"
385
+ />
386
+ </CardContent>
387
+ </Card>
388
+ );
389
+ }
390
+
391
+ // Task with checklist
392
+ const taskDescription = `
393
+ ## Requirements
394
+
395
+ Complete the following items:
396
+
397
+ - [x] Design mockups
398
+ - [x] Backend API
399
+ - [ ] Frontend implementation
400
+ - [ ] Unit tests
401
+ - [ ] Documentation
402
+
403
+ ### Notes
404
+
405
+ Make sure to follow the ||coding standards|| and add proper error handling.
406
+ `;
407
+ ```
408
+
409
+ ### Notification Content
410
+
411
+ ```tsx
412
+ function NotificationDetail({ notification }) {
413
+ return (
414
+ <Alert
415
+ color={notification.type}
416
+ sx={{ mb: 2 }}
417
+ >
418
+ <Markdown
419
+ content={notification.message}
420
+ defaultLevel="body-sm"
421
+ accentColor={notification.type === 'success' ? 'success.600' : 'danger.600'}
422
+ />
423
+ </Alert>
424
+ );
425
+ }
426
+
427
+ // Notification with formatting
428
+ const notification = {
429
+ type: 'success',
430
+ message: 'Your order **#12345** has been ||shipped||! Track it [here](/tracking).',
431
+ };
432
+ ```
433
+
434
+ ### Email Preview
435
+
436
+ ```tsx
437
+ function EmailPreview({ subject, body }) {
438
+ return (
439
+ <Card variant="outlined">
440
+ <CardContent>
441
+ <Typography level="title-md" sx={{ mb: 2 }}>
442
+ {subject}
443
+ </Typography>
444
+ <Divider sx={{ mb: 2 }} />
445
+ <Markdown
446
+ content={body}
447
+ defaultLevel="body-md"
448
+ defaultLinkAction="_blank"
449
+ />
450
+ </CardContent>
451
+ </Card>
452
+ );
453
+ }
454
+ ```
455
+
456
+ ### API Documentation
457
+
458
+ ```tsx
459
+ function APIDocumentation({ endpoint }) {
460
+ return (
461
+ <Box>
462
+ <Typography level="h2">{endpoint.name}</Typography>
463
+ <Chip color="primary" sx={{ mb: 2 }}>
464
+ {endpoint.method}
465
+ </Chip>
466
+ <Markdown
467
+ content={endpoint.description}
468
+ defaultLevel="body-md"
469
+ />
470
+ </Box>
471
+ );
472
+ }
473
+
474
+ const endpointDoc = `
475
+ ### Request
476
+
477
+ \`\`\`bash
478
+ curl -X POST https://api.example.com/users \\
479
+ -H "Authorization: Bearer token" \\
480
+ -d '{"name": "John"}'
481
+ \`\`\`
482
+
483
+ ### Response
484
+
485
+ | Field | Type | Description |
486
+ |-------|------|-------------|
487
+ | id | string | User ID |
488
+ | name | string | User name |
489
+ | createdAt | string | ISO timestamp |
490
+
491
+ ### Example Response
492
+
493
+ \`\`\`json
494
+ {
495
+ "id": "user_123",
496
+ "name": "John",
497
+ "createdAt": "2024-01-01T00:00:00Z"
498
+ }
499
+ \`\`\`
500
+ `;
501
+ ```
502
+
503
+ ## Props and Customization
504
+
505
+ ### Key Props
506
+
507
+ | Prop | Type | Default | Description |
508
+ | ------------------- | -------------------------------------------------------------- | -------------- | ----------------------------------------- |
509
+ | `content` | `string` | - | Markdown content to render |
510
+ | `defaultLevel` | `TypographyLevel` | `'body-md'` | Base typography level |
511
+ | `defaultLinkAction` | `'_self' \| '_blank' \| '_parent' \| '_top'` | `'_self'` | Link target behavior |
512
+ | `color` | `'primary' \| 'neutral' \| 'danger' \| 'success' \| 'warning'` | - | Color theme |
513
+ | `textColor` | `string` | - | Specific text color (e.g., 'primary.500') |
514
+ | `accentColor` | `string` | `'danger.500'` | Color for `\|\|text\|\|` syntax |
515
+ | `textAlign` | `'left' \| 'center' \| 'right'` | `'left'` | Text alignment |
516
+ | `fontWeight` | `number \| string` | - | Base font weight |
517
+ | `boldFontWeight` | `'sm' \| 'md' \| 'lg' \| 'xl'` | - | Bold text font weight |
518
+
519
+ ### Supported Markdown Syntax
520
+
521
+ ````markdown
522
+ ## Text Formatting
523
+
524
+ **Bold text** using `**text**`
525
+ *Italic text* using `*text*`
526
+ ~Strikethrough~ using `~text~`
527
+ `Inline code` using backticks
528
+ ||Accent color|| using `||text||`
529
+
530
+ ## Headings
531
+
532
+ # Heading 1
533
+ ## Heading 2
534
+ ### Heading 3
535
+
536
+ ## Links
537
+
538
+ [Link text](https://example.com)
539
+ https://auto-linked-url.com
540
+
541
+ ## Lists
542
+
543
+ ### Unordered
544
+ - Item 1
545
+ - Item 2
546
+ - Nested item
547
+
548
+ ### Ordered
549
+ 1. First
550
+ 2. Second
551
+ 3. Third
552
+
553
+ ### Task List
554
+ - [x] Completed
555
+ - [ ] Pending
556
+
557
+ ## Blockquotes
558
+
559
+ > Quoted text
560
+ > Multiple lines
561
+
562
+ ## Code Blocks
563
+
564
+ ```javascript
565
+ const code = 'highlighted';
566
+ ````
567
+
568
+ ## Tables
569
+
570
+ | Header 1 | Header 2 |
571
+ | -------- | -------- |
572
+ | Cell 1 | Cell 2 |
573
+
574
+ ## Horizontal Rule
575
+
576
+ ***
577
+
578
+ ````
579
+
580
+ ### Typography Levels
581
+
582
+ ```tsx
583
+ // Title levels
584
+ <Markdown content="..." defaultLevel="title-lg" />
585
+ <Markdown content="..." defaultLevel="title-md" />
586
+ <Markdown content="..." defaultLevel="title-sm" />
587
+
588
+ // Body levels
589
+ <Markdown content="..." defaultLevel="body-lg" />
590
+ <Markdown content="..." defaultLevel="body-md" /> // default
591
+ <Markdown content="..." defaultLevel="body-sm" />
592
+ <Markdown content="..." defaultLevel="body-xs" />
593
+ ````
594
+
595
+ ### Color Options
596
+
597
+ ```tsx
598
+ // Theme colors
599
+ <Markdown content="..." color="primary" />
600
+ <Markdown content="..." color="neutral" />
601
+ <Markdown content="..." color="success" />
602
+ <Markdown content="..." color="warning" />
603
+ <Markdown content="..." color="danger" />
604
+
605
+ // Specific text colors
606
+ <Markdown content="..." textColor="primary.500" />
607
+ <Markdown content="..." textColor="common.black" />
608
+ ```
609
+
610
+ ### Link Behavior
611
+
612
+ ```tsx
613
+ // Open in same tab (default)
614
+ <Markdown content="[Link](url)" defaultLinkAction="_self" />
615
+
616
+ // Open in new tab
617
+ <Markdown content="[Link](url)" defaultLinkAction="_blank" />
618
+ ```
619
+
620
+ ### Accent Color Highlighting
621
+
622
+ ```tsx
623
+ // Custom accent color for ||text|| syntax
624
+ <Markdown
625
+ content="This is ||highlighted|| text"
626
+ accentColor="success.500"
627
+ />
628
+
629
+ // Default accent color is danger.500
630
+ <Markdown content="This is ||highlighted|| text" />
631
+ ```
632
+
633
+ ## Accessibility
634
+
635
+ Markdown renders semantic HTML elements with proper accessibility:
636
+
637
+ ### Semantic Structure
638
+
639
+ - Headings render as `<h1>` through `<h6>`
640
+ - Lists render as `<ul>`, `<ol>`, and `<li>`
641
+ - Links render as `<a>` with proper attributes
642
+ - Code blocks have appropriate `<pre>` and `<code>` tags
643
+ - Tables use semantic `<table>`, `<thead>`, `<tbody>` structure
644
+
645
+ ### Link Accessibility
646
+
647
+ ```tsx
648
+ // Links opening in new tabs should have proper attributes
649
+ // The component handles rel="noopener noreferrer" automatically
650
+ <Markdown
651
+ content="[External link](https://example.com)"
652
+ defaultLinkAction="_blank"
653
+ />
654
+ ```
655
+
656
+ ### Screen Reader Considerations
657
+
658
+ - Task list items announce their checked state
659
+ - Blockquotes are properly indicated
660
+ - Tables have proper header associations
661
+
662
+ ### Color Contrast
663
+
664
+ ```tsx
665
+ // Ensure sufficient contrast with text colors
666
+ <Markdown
667
+ content="..."
668
+ textColor="neutral.800" // Good contrast
669
+ />
670
+ ```
671
+
672
+ ## Best Practices
673
+
674
+ ### ✅ Do
675
+
676
+ 1. **Sanitize user content**: Always sanitize markdown from untrusted sources
677
+
678
+ ```tsx
679
+ // ✅ Good: Sanitize before rendering
680
+ import sanitize from 'sanitize-html';
681
+
682
+ <Markdown content={sanitize(userContent)} />
683
+ ```
684
+
685
+ 2. **Match typography to context**: Use appropriate levels for the content type
686
+
687
+ ```tsx
688
+ // ✅ Good: Match level to context
689
+ <Markdown content={articleBody} defaultLevel="body-md" />
690
+ <Markdown content={footnote} defaultLevel="body-xs" />
691
+ ```
692
+
693
+ 3. **Configure link behavior appropriately**: External links should open in new tabs
694
+
695
+ ```tsx
696
+ // ✅ Good: External links in new tab
697
+ <Markdown
698
+ content={externalContent}
699
+ defaultLinkAction="_blank"
700
+ />
701
+ ```
702
+
703
+ 4. **Use accent colors meaningfully**: Highlight important information
704
+
705
+ ```tsx
706
+ // ✅ Good: Highlight key information
707
+ <Markdown
708
+ content="Your balance is ||$1,234.56||"
709
+ accentColor="success.500"
710
+ />
711
+ ```
712
+
713
+ ### ❌ Don't
714
+
715
+ 1. **Don't use for complex layouts**: Use proper components instead
716
+
717
+ ```tsx
718
+ // ❌ Bad: Complex tables in markdown
719
+ <Markdown content={complexDataTable} />
720
+
721
+ // ✅ Good: Use DataTable component
722
+ <DataTable columns={columns} rows={rows} />
723
+ ```
724
+
725
+ 2. **Don't ignore security**: Never render untrusted content directly
726
+
727
+ ```tsx
728
+ // ❌ Bad: Rendering untrusted content
729
+ <Markdown content={userInput} />
730
+
731
+ // ✅ Good: Sanitize first
732
+ <Markdown content={sanitizeMarkdown(userInput)} />
733
+ ```
734
+
735
+ 3. **Don't use for UI labels**: Use Typography for interface text
736
+
737
+ ```tsx
738
+ // ❌ Bad: Markdown for button labels
739
+ <Markdown content="**Submit**" />
740
+
741
+ // ✅ Good: Typography for UI
742
+ <Typography fontWeight="lg">Submit</Typography>
743
+ ```
744
+
745
+ 4. **Don't mix markdown with complex interactivity**: Keep it content-focused
746
+
747
+ ```tsx
748
+ // ❌ Bad: Trying to add interactive elements via markdown
749
+ <Markdown content="Click [here](javascript:void(0))" />
750
+
751
+ // ✅ Good: Use proper components for interactivity
752
+ <Box>
753
+ <Markdown content="Complete the form below:" />
754
+ <Button onClick={handleSubmit}>Submit</Button>
755
+ </Box>
756
+ ```
757
+
758
+ ## Performance Considerations
759
+
760
+ ### Memoize Content
761
+
762
+ For frequently re-rendering parents, memoize the Markdown component:
763
+
764
+ ```tsx
765
+ const MemoizedMarkdown = memo(({ content, ...props }) => (
766
+ <Markdown content={content} {...props} />
767
+ ));
768
+
769
+ function ParentComponent({ content }) {
770
+ return (
771
+ <Box>
772
+ <MemoizedMarkdown content={content} defaultLevel="body-md" />
773
+ </Box>
774
+ );
775
+ }
776
+ ```
777
+
778
+ ### Lazy Load Long Content
779
+
780
+ For very long documents, consider lazy loading:
781
+
782
+ ```tsx
783
+ function LazyMarkdown({ content }) {
784
+ const [isVisible, setIsVisible] = useState(false);
785
+ const ref = useRef<HTMLDivElement>(null);
786
+
787
+ useEffect(() => {
788
+ const observer = new IntersectionObserver(
789
+ ([entry]) => {
790
+ if (entry.isIntersecting) {
791
+ setIsVisible(true);
792
+ observer.disconnect();
793
+ }
794
+ },
795
+ { threshold: 0.1 }
796
+ );
797
+
798
+ if (ref.current) {
799
+ observer.observe(ref.current);
800
+ }
801
+
802
+ return () => observer.disconnect();
803
+ }, []);
804
+
805
+ return (
806
+ <Box ref={ref}>
807
+ {isVisible ? (
808
+ <Markdown content={content} />
809
+ ) : (
810
+ <Skeleton variant="rectangular" height={200} />
811
+ )}
812
+ </Box>
813
+ );
814
+ }
815
+ ```
816
+
817
+ ### Split Large Documents
818
+
819
+ For very large documents, split into sections:
820
+
821
+ ```tsx
822
+ function LargeDocument({ sections }) {
823
+ return (
824
+ <Stack gap={4}>
825
+ {sections.map((section, index) => (
826
+ <Box key={index}>
827
+ <Markdown content={section} defaultLevel="body-md" />
828
+ {index < sections.length - 1 && <Divider />}
829
+ </Box>
830
+ ))}
831
+ </Stack>
832
+ );
833
+ }
834
+ ```
835
+
836
+ ### Avoid Unnecessary Re-parsing
837
+
838
+ Keep content stable when possible:
839
+
840
+ ```tsx
841
+ // ❌ Bad: Creating new string on each render
842
+ <Markdown content={`Hello, ${name}!`} />
843
+
844
+ // ✅ Good: Memoize dynamic content
845
+ const content = useMemo(() => `Hello, ${name}!`, [name]);
846
+ <Markdown content={content} />
847
+ ```
848
+
849
+ Markdown provides a powerful way to render formatted text content in your application. Use it for documentation, user-generated content, and any scenario requiring rich text display. Always sanitize untrusted content, match typography levels to your context, and consider performance for large documents.