fix: only add nostr: for valid nip19
This commit is contained in:
parent
84ef234d38
commit
e2454405ad
1 changed files with 8 additions and 1 deletions
|
|
@ -1,6 +1,13 @@
|
||||||
|
import { nip19 } from 'nostr-tools'
|
||||||
|
|
||||||
export function preprocessContent(content: string) {
|
export function preprocessContent(content: string) {
|
||||||
const regex = /(?<=^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g
|
const regex = /(?<=^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g
|
||||||
return content.replace(regex, (match) => {
|
return content.replace(regex, (match) => {
|
||||||
return `nostr:${match}`
|
try {
|
||||||
|
nip19.decode(match)
|
||||||
|
return `nostr:${match}`
|
||||||
|
} catch {
|
||||||
|
return match
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue