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:
parent
b846c5720c
commit
84ad3556a7
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user