import Link from 'next/link'; import * as React from 'react'; import { useEffect } from 'react'; import ReactMarkdown from 'react-markdown'; import rehypeRaw from 'rehype-raw'; export interface IMarkdownProps { content: string | undefined; } export const Markdown: React.FunctionComponent = ({content}: React.PropsWithChildren) => { const getTitle = (props: any) => { const title = props?.children.length > 0 ? `${props?.children[0] as string}` : ""; return title; }; const generateId = (props: any) => { const title = getTitle(props); return title.toLowerCase().replace(/\s/g, '-'); }; useEffect(() => { const elms = document.querySelectorAll('blockquote > p > strong'); for (let i = 0; i < elms.length; i++) { const elm = elms[i]; if (elm.textContent?.toLowerCase() === "important") { elm.parentElement?.parentElement?.classList.add('important'); } } }, ['']); if (!content) { return null; } return (
{/* eslint-disable react/no-children-prop */} { const url = props?.href || ""; const title = getTitle(props); const elm = {title}; return elm; }, h1: ({node, ...props}) => (

{getTitle(props)}

), h2: ({node, ...props}) => (

{getTitle(props)}

), h3: ({node, ...props}) => (

{getTitle(props)}

), }} rehypePlugins={[rehypeRaw]} children={content} />
); };