import { cn } from '@/lib/utils'; import { useEffect, useState } from 'react'; import { Marked } from 'marked'; import hljs from 'highlight.js'; import { markedHighlight } from 'marked-highlight'; const markedAndHighlight = new Marked( markedHighlight({ emptyLangClass: 'hljs', langPrefix: 'hljs language-', highlight(code, lang, info) { const language = hljs.getLanguage(lang) ? lang : 'plaintext'; return hljs.highlight(code, { language }).value; }, }), ); export const md2html = async (md: string) => { const html = markedAndHighlight.parse(md); return html; }; export const clearMeta = (markdown?: string) => { if (!markdown) return ''; // Remove YAML front matter if present const yamlRegex = /^---\n[\s\S]*?\n---\n/; return markdown.replace(yamlRegex, ''); }; type Props = { children?: React.ReactNode; className?: string; style?: React.CSSProperties; content?: string; // Optional content prop for markdown text [key: string]: any; // Allow any additional props }; export const MarkdownPreview = (props: Props) => { return (