Tend your corner of the atmosphere. spores.garden turns your AT Protocol records into a personal site with unique themes. Your data never leaves your PDS. Grow something that's truly yours.
spores.garden
1/**
2 * Secure Markdown Rendering
3 *
4 * Uses marked for parsing and DOMPurify for sanitization.
5 */
6
7import { marked } from 'marked';
8import { sanitizeHtml } from './sanitize';
9
10// Configure marked for safe rendering
11marked.setOptions({
12 gfm: true, // GitHub Flavored Markdown
13 breaks: true, // Convert \n to <br>
14});
15
16/**
17 * Render markdown to sanitized HTML.
18 * Safe for user-generated content.
19 */
20export function renderMarkdown(text: string): string {
21 const raw = marked.parse(text, { async: false }) as string;
22 return sanitizeHtml(raw);
23}
24
25/**
26 * Check if text appears to contain markdown formatting.
27 */
28export function looksLikeMarkdown(text: string): boolean {
29 return /^#|\*\*|__|\[.*\]\(|\n-\s|\n\d+\./.test(text);
30}