cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / lib / markdown.ts

src/lib/markdown.ts · 28 lines · 728 B← back to folder
1import { unified } from "unified";
2import remarkParse from "remark-parse";
3import remarkGfm from "remark-gfm";
4import remarkRehype from "remark-rehype";
5import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
6import rehypeStringify from "rehype-stringify";
7
8const sanitizeSchema = {
9 ...defaultSchema,
10 protocols: {
11 ...defaultSchema.protocols,
12 href: ["http", "https", "mailto"],
13 src: ["http", "https"],
14 },
15};
16
17export async function renderMarkdown(markdown: string): Promise<string> {
18 const file = await unified()
19 .use(remarkParse)
20 .use(remarkGfm)
21 .use(remarkRehype)
22 .use(rehypeSanitize, sanitizeSchema)
23 .use(rehypeStringify)
24 .process(markdown || "");
25
26 return String(file);
27}
28
cg / hackerproducts — hacker products