💂♂️ fixed lint and prittier
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
'use client';
|
||||
'use client'
|
||||
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
import { CodeBlock } from './code-block';
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { CodeBlock } from './code-block'
|
||||
|
||||
interface MarkdownRendererProps {
|
||||
content: string;
|
||||
content: string
|
||||
}
|
||||
|
||||
export default function MarkdownRenderer({ content }: MarkdownRendererProps) {
|
||||
@@ -16,48 +16,42 @@ export default function MarkdownRenderer({ content }: MarkdownRendererProps) {
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
h1: ({ children }) => {
|
||||
const text = String(children);
|
||||
const id = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');
|
||||
return <h1 id={id}>{children}</h1>;
|
||||
const text = String(children)
|
||||
const id = text
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/(^-|-$)/g, '')
|
||||
return <h1 id={id}>{children}</h1>
|
||||
},
|
||||
h2: ({ children }) => {
|
||||
const text = String(children);
|
||||
const id = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');
|
||||
return <h2 id={id}>{children}</h2>;
|
||||
const text = String(children)
|
||||
const id = text
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/(^-|-$)/g, '')
|
||||
return <h2 id={id}>{children}</h2>
|
||||
},
|
||||
h3: ({ children }) => {
|
||||
const text = String(children);
|
||||
const id = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');
|
||||
return <h3 id={id}>{children}</h3>;
|
||||
const text = String(children)
|
||||
const id = text
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/(^-|-$)/g, '')
|
||||
return <h3 id={id}>{children}</h3>
|
||||
},
|
||||
code: ({ inline, className, children, ...props }: any) => {
|
||||
const match = /language-(\w+)/.exec(className || '');
|
||||
const match = /language-(\w+)/.exec(className || '')
|
||||
if (!inline && match) {
|
||||
return (
|
||||
<CodeBlock
|
||||
code={String(children).replace(/\n$/, '')}
|
||||
language={match[1]}
|
||||
/>
|
||||
);
|
||||
return <CodeBlock code={String(children).replace(/\n$/, '')} language={match[1]} />
|
||||
}
|
||||
return (
|
||||
<code {...props}>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
return <code {...props}>{children}</code>
|
||||
},
|
||||
img: ({ src, alt }) => {
|
||||
if (!src || typeof src !== 'string') return null;
|
||||
const isExternal = src.startsWith('http://') || src.startsWith('https://');
|
||||
if (!src || typeof src !== 'string') return null
|
||||
const isExternal = src.startsWith('http://') || src.startsWith('https://')
|
||||
|
||||
if (isExternal) {
|
||||
return (
|
||||
<img
|
||||
src={src}
|
||||
alt={alt || ''}
|
||||
className="w-full h-auto"
|
||||
/>
|
||||
);
|
||||
return <img src={src} alt={alt || ''} className="w-full h-auto" />
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -70,33 +64,25 @@ export default function MarkdownRenderer({ content }: MarkdownRendererProps) {
|
||||
style={{ width: '100%', height: 'auto' }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
},
|
||||
a: ({ href, children }) => {
|
||||
if (!href) return <>{children}</>;
|
||||
const isExternal = href.startsWith('http://') || href.startsWith('https://');
|
||||
if (!href) return <>{children}</>
|
||||
const isExternal = href.startsWith('http://') || href.startsWith('https://')
|
||||
|
||||
if (isExternal) {
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<a href={href} target="_blank" rel="noopener noreferrer">
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={href}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
return <Link href={href}>{children}</Link>
|
||||
},
|
||||
}}
|
||||
>
|
||||
{content}
|
||||
</ReactMarkdown>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user