diff --git a/src/stores/note.ts b/src/stores/note.ts index 0d800dd..d2af302 100644 --- a/src/stores/note.ts +++ b/src/stores/note.ts @@ -307,14 +307,24 @@ type NoteStore = { } export const referencesToTags = (value: string) => { - const regex = + const regexHashtag = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig; + const regexMention = /\bnostr:((note|npub|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g; + let hashtags: string[] = []; let refs: string[] = []; let tags: string[][] = []; let match; - while((match = regex.exec(value)) !== null) { + // Parse hashtags to add to tags + while((match = regexHashtag.exec(value)) != null) { + hashtags.push(match[0]); + } + + tags = hashtags.map(h => ['t', h.slice(2)]); + + // Parse mentions to add to tags + while((match = regexMention.exec(value)) !== null) { refs.push(match[0]); }