initial commit
This commit is contained in:
20
lib/markdown.ts
Normal file
20
lib/markdown.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { remark } from "remark";
|
||||
import remarkParse from "remark-parse";
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import rehypeStringify from "rehype-stringify";
|
||||
import remarkRehype from "remark-rehype";
|
||||
|
||||
/**
|
||||
* Identical to renderMarkdown() in portfolio/data/content.ts, so the preview
|
||||
* renders exactly what the live post page will. allowDangerousHtml is
|
||||
* intentional: posts embed raw HTML blocks (e.g. <blockquote>).
|
||||
*/
|
||||
export async function renderMarkdown(source: string): Promise<string> {
|
||||
const re = await remark()
|
||||
.use(remarkParse)
|
||||
.use(remarkRehype, { allowDangerousHtml: true })
|
||||
.use(rehypeRaw)
|
||||
.use(rehypeStringify)
|
||||
.process(source);
|
||||
return re?.toString() ?? "";
|
||||
}
|
||||
Reference in New Issue
Block a user