fix: preserve linebreaks between URLs and Nostr references in editor (#657)

Co-authored-by: The Daniel <dmnyc@users.noreply.github.com>
This commit is contained in:
The Daniel ⚡️
2025-11-12 21:01:06 -05:00
committed by GitHub
parent 8ed28a79b1
commit e544c0a801

View File

@@ -4,12 +4,13 @@ import { JSONContent } from '@tiptap/react'
import { nip19 } from 'nostr-tools'
export function parseEditorJsonToText(node?: JSONContent) {
const text = _parseEditorJsonToText(node).trim()
const regex = /(?:^|\s|@)(nostr:)?(nevent|naddr|nprofile|npub)1[a-zA-Z0-9]+/g
const text = _parseEditorJsonToText(node)
const regex = /(^|\s+|@)(nostr:)?(nevent|naddr|nprofile|npub)1[a-zA-Z0-9]+/g
return text.replace(regex, (match) => {
return text.replace(regex, (match, leadingWhitespace) => {
let bech32 = match.trim()
const leadingSpace = match.startsWith(' ') ? ' ' : ''
const whitespace = leadingWhitespace || ''
if (bech32.startsWith('@nostr:')) {
bech32 = bech32.slice(7)
} else if (bech32.startsWith('@')) {
@@ -20,11 +21,11 @@ export function parseEditorJsonToText(node?: JSONContent) {
try {
nip19.decode(bech32)
return `${leadingSpace}nostr:${bech32}`
return `${whitespace}nostr:${bech32}`
} catch {
return match
}
})
}).trim()
}
function _parseEditorJsonToText(node?: JSONContent): string {