diff --git a/src/components/Notes/NoteRender.tsx b/src/components/Notes/NoteRender.tsx index 907eeba..0cf982b 100644 --- a/src/components/Notes/NoteRender.tsx +++ b/src/components/Notes/NoteRender.tsx @@ -6,19 +6,19 @@ 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 + /(?: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,}/gi + /(?:nostr:|@)?(?:npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/i const nostrEntity = - /(npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi -const nostrNip5Mention = /(?:nostr:|@)([^\s]{1,64}@[^\s]+\.[^\s]{2,})/gi + /(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(() => { @@ -26,68 +26,81 @@ export const NoteRender = ({ content }: NoteRenderProps) => { const parts = content.split( new RegExp( - `(${link.source})|(${nostrMention.source})|${nostrNip5Mention.source}`, + `(${link.source})|(${nostrMention.source})|(${nostrNip05Mention.source})`, 'gui' ) ) - const _parts = parts.map((part, index) => { - if (link.test(part)) { - const [href] = part.match(link) || [] + 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