-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdownViewer.jsx
More file actions
30 lines (27 loc) · 1013 Bytes
/
MarkdownViewer.jsx
File metadata and controls
30 lines (27 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import DOMPurify from 'isomorphic-dompurify';
import * as style from './MarkdownViewer.module.css';
/**
* Lightweight shared markdown viewer component
*
* This component is deliberately lightweight - it only displays pre-processed HTML.
* No markdown libraries are imported here, keeping the bundle size minimal.
*
* Processing happens in the consuming components:
* - Server component: processes markdown server-side (heavy libs stay on server)
* - Client component: processes markdown client-side (heavy libs go to client)
*
* All HTML is sanitized using DOMPurify to prevent XSS attacks.
*
* This pattern ensures the viewer itself has minimal bundle impact.
*/
const MarkdownViewer = ({ processedHtml, className }) => {
const sanitizedHtml = DOMPurify.sanitize(processedHtml);
return (
<div
className={`${style.markdownContent} ${className || ''}`}
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
/>
);
};
export default MarkdownViewer;