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 { getIdFromYoutubeLink, isValidAudioUrl, isValidImageUrl, isValidUrl, isValidVideoUrl, isYoutubeLink } from 'utils' interface NoteRenderProps { content: string } const link = /(?:https?:\/\/|www\.)(?:[a-zA-Z0-9.-]+\.[a-zA-Z]+(?::\d+)?)(?:[/?#][\p{L}\p{N}\p{M}&.-/?=#\-@%+_,:!~*]*)?/u const nostrMention = /(?:nostr:|@)?(?:npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/i const nostrEntity = /(npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/i const nostrNip05Mention = /(?:nostr:|@)[^\s]{1,64}@[^\s]+\.[^\s]{2,}/i const nip05Entity = /(?:nostr:|@)([^\s]{1,64}@[^\s]+\.[^\s]{2,})/i export const NoteRender = ({ content }: NoteRenderProps) => { const _content = useMemo(() => { if (!content) return const parts = content.split( new RegExp( `(${link.source})|(${nostrMention.source})|(${nostrNip05Mention.source})`, 'gui' ) ) const _parts = parts .filter((p) => typeof p !== 'undefined') .map((part, index) => { const key = `${index}-${part}` if (link.test(part)) { const [href] = part.match(link) || [] if (href && isValidUrl(href)) { if (isValidImageUrl(href)) { // Image return ( ) } else if (isValidVideoUrl(href)) { // Video return (