diff --git a/src/components/UniversalContent/SimpleContent.tsx b/src/components/UniversalContent/SimpleContent.tsx index c2fde67..8fdc8ca 100644 --- a/src/components/UniversalContent/SimpleContent.tsx +++ b/src/components/UniversalContent/SimpleContent.tsx @@ -1,9 +1,11 @@ import { useMemo } from 'react' -import { cn } from '@/lib/utils' import { cleanUrl } from '@/lib/url' -import { getImetaInfosFromEvent } from '@/lib/event' import { Event } from 'nostr-tools' -import ImageWithLightbox from '../ImageWithLightbox' +import Markdown from 'react-markdown' +import remarkGfm from 'remark-gfm' +import { remarkNostr } from '../Note/LongFormArticle/remarkNostr' +import NostrNode from '../Note/LongFormArticle/NostrNode' +import { cn } from '@/lib/utils' interface SimpleContentProps { event?: Event @@ -16,8 +18,6 @@ export default function SimpleContent({ content, className }: SimpleContentProps) { - const imetaInfos = useMemo(() => event ? getImetaInfosFromEvent(event) : [], [event]) - const processedContent = useMemo(() => { const rawContent = content || event?.content || '' @@ -36,83 +36,54 @@ export default function SimpleContent({ return cleaned }, [content, event?.content]) - const renderContent = () => { - if (!processedContent) return null - - // Split content by lines and process each line - const lines = processedContent.split('\n') - const elements: JSX.Element[] = [] - let key = 0 - - lines.forEach((line) => { - // Check if line contains an image URL - const imageMatch = line.match(/(https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|heic|svg))/i) - - if (imageMatch) { - const imageUrl = imageMatch[1] - const imageInfo = imetaInfos.find((info) => info.url === imageUrl) - const imageData = imageInfo || { url: imageUrl, pubkey: event?.pubkey } - - elements.push( -
- -
- ) - - // Add the rest of the line as text if there's anything else - const beforeImage = line.substring(0, imageMatch.index).trim() - const afterImage = line.substring(imageMatch.index! + imageUrl.length).trim() - - if (beforeImage || afterImage) { - elements.push( -
- {beforeImage && {beforeImage}} - {afterImage && {afterImage}} -
- ) - } - } else { - // Regular text line - elements.push( -
- {renderTextWithLinks(line)} -
- ) - } - }) - - return elements - } - - const renderTextWithLinks = (text: string) => { - // Simple link detection and rendering - const linkRegex = /(https?:\/\/[^\s]+)/g - const parts = text.split(linkRegex) - - return parts.map((part, index) => { - if (linkRegex.test(part)) { - return ( - - {part} - - ) + const components = useMemo(() => ({ + nostr: ({ rawText, bech32Id }: { rawText: string; bech32Id: string }) => ( + + ), + a: ({ href, children, ...props }: any) => { + if (!href) { + return } - return {part} - }) - } + return ( + + {children} + + ) + }, + p: (props: any) =>

, + code: (props: any) => , + pre: (props: any) =>

,
+    blockquote: (props: any) => 
, + ul: (props: any) =>
    , + ol: (props: any) =>
      , + li: (props: any) =>
    1. , + h1: (props: any) =>

      , + h2: (props: any) =>

      , + h3: (props: any) =>

      , + strong: (props: any) => , + em: (props: any) => + }), []) return ( -
      - {renderContent()} +
      + { + if (url.startsWith('nostr:')) { + return url.slice(6) // Remove 'nostr:' prefix for rendering + } + return url + }} + components={components} + > + {processedContent} +
      ) }