From 49917ec1a0114810ebc66f1dd4d803ca08b51549 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 17 Feb 2026 02:34:50 -0600 Subject: [PATCH] Preserve newlines between text and naddr URL in note content The whitespace collapsing logic was stripping newlines before naddr-embed tokens that have a URL, causing text and the URL to smash together. Now only pure block embeds (no URL) trim preceding whitespace. Co-authored-by: shakespeare.diy --- src/components/NoteContent.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/NoteContent.tsx b/src/components/NoteContent.tsx index 558ed7c7..41b01023 100644 --- a/src/components/NoteContent.tsx +++ b/src/components/NoteContent.tsx @@ -162,9 +162,14 @@ export function NoteContent({ // so that newlines surrounding a URL don't stack with the card's own spacing. for (let i = 0; i < result.length; i++) { const token = result[i]; - if (token.type === 'link-preview' || token.type === 'youtube-embed' || token.type === 'nevent-embed' || token.type === 'naddr-embed') { - // Trim trailing whitespace from the preceding text token - if (i > 0) { + const isBlock = token.type === 'link-preview' || token.type === 'youtube-embed' || token.type === 'nevent-embed' + || (token.type === 'naddr-embed' && !token.url); + // naddr-embed with a URL starts with inline text, so only trim after it + const isNaddrWithUrl = token.type === 'naddr-embed' && !!token.url; + + if (isBlock || isNaddrWithUrl) { + // Trim trailing whitespace from the preceding text token (only for pure block tokens) + if (isBlock && i > 0) { const prev = result[i - 1]; if (prev.type === 'text') { prev.value = prev.value.replace(/\s+$/, '');