fix: update regex and improve bech32 handling in parseEditorJsonToText
This commit is contained in:
@@ -5,15 +5,19 @@ import { nip19 } from 'nostr-tools'
|
||||
|
||||
export function parseEditorJsonToText(node?: JSONContent) {
|
||||
const text = _parseEditorJsonToText(node).trim()
|
||||
const regex = /(?:^|\s)(nevent|naddr|nprofile|npub)1[a-zA-Z0-9]+/g
|
||||
const regex = /(?:@|nostr:)?(nevent|naddr|nprofile|npub)1[a-zA-Z0-9]+/g
|
||||
|
||||
return text.replace(regex, (match) => {
|
||||
const trimmed = match.trim()
|
||||
const leadingSpace = match.startsWith(' ') ? ' ' : ''
|
||||
let bech32 = match.trim()
|
||||
if (bech32.startsWith('@')) {
|
||||
bech32 = bech32.slice(1)
|
||||
} else if (bech32.startsWith('nostr:')) {
|
||||
bech32 = bech32.slice(6)
|
||||
}
|
||||
|
||||
try {
|
||||
nip19.decode(trimmed)
|
||||
return `${leadingSpace}nostr:${trimmed}`
|
||||
nip19.decode(bech32)
|
||||
return `nostr:${bech32}`
|
||||
} catch {
|
||||
return match
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user