diff --git a/apps/web/src/components/markdown/markdown-image.tsx b/apps/web/src/components/markdown/markdown-image.tsx new file mode 100644 index 00000000..9984911a --- /dev/null +++ b/apps/web/src/components/markdown/markdown-image.tsx @@ -0,0 +1,55 @@ +"use client"; + +import React, { useState } from 'react'; +import Image from 'next/image'; + +interface MarkdownImageProps { + src: string; + alt?: string; +} + +const MarkdownImage: React.FC = ({ src, alt }) => { + const [imageSize, setImageSize] = useState({ width: 1, height: 1 }); + + return ( +
+ {alt { + setImageSize({ + width: target.naturalWidth, + height: target.naturalHeight, + }); + }} + width={imageSize.width} + height={imageSize.height} + /> + {alt && ( +
+ {alt} +
+ )} +
+ ); +}; + +export default MarkdownImage; diff --git a/apps/web/src/components/markdown/markdown-renderer.tsx b/apps/web/src/components/markdown/markdown-renderer.tsx index 89a57e51..5ead363f 100644 --- a/apps/web/src/components/markdown/markdown-renderer.tsx +++ b/apps/web/src/components/markdown/markdown-renderer.tsx @@ -1,14 +1,12 @@ -"use client"; - -import React, { useState } from 'react'; +import React from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeRaw from 'rehype-raw'; -import Image from 'next/image'; import Anchor from './anchor'; import BlockQuote from './block-quote'; import CodeBlock from './code-block'; +import MarkdownImage from './markdown-image'; interface MarkdownRendererProps { content: string; @@ -33,47 +31,7 @@ const MarkdownRenderer: React.FC = ({ content }) => ( a: (props) => , sup: 'sup', sub: 'sub', - img: (props) => { - const [imageSize, setImageSize] = useState({ width: 1, height: 1 }); - - return ( -
- {props.alt { - setImageSize({ - width: target.naturalWidth, - height: target.naturalHeight, - }); - }} - width={imageSize.width} - height={imageSize.height} - /> - {props.alt && ( -
- {props.alt} -
- )} -
- ); - }, + img: (props) => , ul: (props) => (