only replace note ID when note ID starts with `@` character (#441)

* only replace note ID when note ID is surrounded by space chars

This prevents partial parts of links with note IDs from being converted to a tag.

* make sure to keep whitespace around note ID

* improve var name

* allow users to prefix note ID with an @

* require notes to be prefixed with `@`
This commit is contained in:
Sam Samskies 2023-03-15 15:02:54 -10:00 committed by GitHub
parent b846c5720c
commit 84ad3556a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -59,8 +59,9 @@ export default function useEventPublisher() {
}
};
const replaceNoteId = (match: string) => {
const noteId = match.slice(1);
try {
const hex = bech32ToHex(match);
const hex = bech32ToHex(noteId);
const idx = ev.Tags.length;
ev.Tags.push(new Tag(["e", hex, "", "mention"], idx));
return `#[${idx}]`;
@ -76,7 +77,7 @@ export default function useEventPublisher() {
};
const content = msg
.replace(/@npub[a-z0-9]+/g, replaceNpub)
.replace(/note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId)
.replace(/@note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId)
.replace(HashtagRegex, replaceHashtag);
ev.Content = content;
}