diff --git a/src/components/PrimalMarkdown/PrimalMarkdown.tsx b/src/components/PrimalMarkdown/PrimalMarkdown.tsx index e2c10e2..35e1086 100644 --- a/src/components/PrimalMarkdown/PrimalMarkdown.tsx +++ b/src/components/PrimalMarkdown/PrimalMarkdown.tsx @@ -98,70 +98,85 @@ const account = useAccountContext(); const content = el.innerHTML; - const match = content.match(regex); + const tokens = content.split(regex); - if (match === null || match.length < 2) return el; + let items: any[] = []; - const [nostr, npub] = match; + for(let i=0; i - + items.push( {nostr}} + when={user} + fallback={nostr:{token}} > - @{userName(props.article?.mentionedUsers ? props.article.mentionedUsers[id] : undefined)} + @{userName(user)} - -

- ); - } + ); - if (npub.startsWith('note')) { - const id = npubToHex(npub); - return ( - {nostr}} - > -
- -
-
- ); - } - - if (npub.startsWith('naddr')) { - const mention = props.article?.mentionedNotes && props.article.mentionedNotes[npub]; - - if (!mention) return el; - - const preview = { - url: `/e/${npub}`, - description: (mention.post.tags.find(t => t[0] === 'summary') || [])[1] || mention.post.content.slice(0, 100), - images: [(mention.post.tags.find(t => t[0] === 'image') || [])[1] || mention.user.picture], - title: (mention.post.tags.find(t => t[0] === 'title') || [])[1] || authorName(mention.user), + continue; } - console.log('MENTION: ', mention) - return ; + if (token.startsWith('note')) { + const id = npubToHex(token); + const note = (props.article?.mentionedNotes || {})[id]; + + items.push( + nostr:{token}} + > +
+ +
+
+ ); + + continue; + } + + if (token.startsWith('naddr')) { + const mention = props.article?.mentionedNotes && props.article.mentionedNotes[token]; + + if (!mention) { + items.push(<>nostr:{token}) + continue; + }; + + const preview = { + url: `/e/${token}`, + description: (mention.post.tags.find(t => t[0] === 'summary') || [])[1] || mention.post.content.slice(0, 100), + images: [(mention.post.tags.find(t => t[0] === 'image') || [])[1] || mention.user.picture], + title: (mention.post.tags.find(t => t[0] === 'title') || [])[1] || authorName(mention.user), + } + + items.push( + + ); + + continue; + } + + const elem = document.createElement("span"); + elem.innerHTML = token; + + items.push(<>{elem}); } - return el; + return

{item => <>{item}}

; + };