feat: markdown formatting

This commit is contained in:
michaelessiet
2024-12-30 12:00:51 +01:00
parent 1cbdb82bb5
commit 56185d94fb
5 changed files with 397 additions and 58 deletions

View File

@@ -0,0 +1,31 @@
import { marked } from "marked";
import DOMPurify from "isomorphic-dompurify";
interface MarkedOptions {
gfm: boolean;
breaks: boolean;
headerIds: boolean;
mangle: false;
highlight?: (code: string, lang: string) => string;
}
// Configure marked options
const markedOptions: MarkedOptions = {
gfm: true, // GitHub Flavored Markdown
breaks: true, // Convert \n to <br>
headerIds: true, // Add ids to headers
mangle: false, // Don't escape HTML
highlight: function (code: string, lang: string): string {
// You can add syntax highlighting here if needed
return code;
},
};
marked.setOptions(markedOptions);
// Basic markdown to HTML conversion with sanitization
export default function markdownToHtml(markdown: string) {
const rawHtml = marked.parse(markdown);
console.log(rawHtml);
return DOMPurify.sanitize(rawHtml);
}