import { NDKKind } from '@nostr-dev-kit/ndk' import { ProfileLink } from 'components/ProfileSection' import { nip19 } from 'nostr-tools' import { useMemo } from 'react' import { Fragment } from 'react/jsx-runtime' import { BlogPreview } from './internal/BlogPreview' import { ModPreview } from './internal/ModPreview' import { NoteWrapper } from './internal/NoteWrapper' import { NIP05_REGEX } from 'nostr-tools/nip05' import { isValidImageUrl, isValidUrl, isValidVideoUrl } from 'utils' interface NoteRenderProps { content: string } const link = /(?:https?:\/\/|www\.)(?:[a-zA-Z0-9.-]+\.[a-zA-Z]+(?::\d+)?)(?:[/?#][\p{L}\p{N}\p{M}&.-/?=#\-@%+_,:!~*]*)?/gu const nostrMention = /(?:nostr:|@)?(?:npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi const nostrEntity = /(npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi const nostrNip5Mention = /(?:nostr:|@)([^\s]{1,64}@[^\s]+\.[^\s]{2,})/gi export const NoteRender = ({ content }: NoteRenderProps) => { const _content = useMemo(() => { if (!content) return const parts = content.split( new RegExp( `(${link.source})|(${nostrMention.source})|${nostrNip5Mention.source}`, 'gui' ) ) const _parts = parts.map((part, index) => { if (link.test(part)) { const [href] = part.match(link) || [] if (href && isValidUrl(href)) { if (isValidImageUrl(href)) { // Image return } else if (isValidVideoUrl(href)) { // Video return