Browse Source

fix: only add nostr: for valid nip19

imwald
codytseng 11 months ago
parent
commit
e2454405ad
  1. 7
      src/components/PostEditor/utils.ts

7
src/components/PostEditor/utils.ts

@ -1,6 +1,13 @@ @@ -1,6 +1,13 @@
import { nip19 } from 'nostr-tools'
export function preprocessContent(content: string) {
const regex = /(?<=^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g
return content.replace(regex, (match) => {
try {
nip19.decode(match)
return `nostr:${match}`
} catch {
return match
}
})
}

Loading…
Cancel
Save