'use client' import * as React from 'react' import { Marked } from 'marked' import { markedHighlight } from 'marked-highlight' import hljs from 'highlight.js' import 'highlight.js/styles/github-dark.css' interface ReadmeViewerProps { content: string } export function ReadmeViewer({ content }: ReadmeViewerProps) { const [html, setHtml] = React.useState('') React.useEffect(() => { const marked = new Marked( markedHighlight({ langPrefix: 'hljs language-', highlight(code, lang) { const language = hljs.getLanguage(lang) ? lang : 'plaintext' return hljs.highlight(code, { language }).value }, }) ) // Configure marked options marked.setOptions({ gfm: true, breaks: true, }) // Parse markdown const parseMarkdown = async () => { const result = await marked.parse(content) setHtml(result) } parseMarkdown() }, [content]) return (
) }