Skip to content

Commit 72ffec2

Browse files
authored
Merge pull request #617 from dmnyc/fix/note-content-newlines
fix(notes): preserve authored newlines in quoted posts
2 parents 1ebe59b + ee8214f commit 72ffec2

4 files changed

Lines changed: 41 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zap.cooking",
33
"license": "MIT",
4-
"version": "4.2.695",
4+
"version": "4.2.696",
55
"private": true,
66
"scripts": {
77
"dev": "vite dev",

src/components/FoodstrFeedOptimized.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
type ReferencedNote
6363
} from '$lib/shareNoteImage';
6464
import { optimizeImageUrl, getOptimalFormat } from '$lib/imageOptimizer';
65+
import { stripQuotedNoteReferences } from '$lib/feed/noteContent';
6566
import { compressedCacheManager, COMPRESSED_FEED_CACHE_CONFIG } from '$lib/compressedCache';
6667
import FeedErrorBoundary from './FeedErrorBoundary.svelte';
6768
import FeedPostSkeleton from './FeedPostSkeleton.svelte';
@@ -1007,14 +1008,7 @@
10071008
// Get content without the quoted note reference (so it doesn't render as inline embed)
10081009
function getContentWithoutQuote(content: string): string {
10091010
try {
1010-
if (!content) return '';
1011-
return content
1012-
.replace(
1013-
/nostr:(nevent1[023456789acdefghjklmnpqrstuvwxyz]+|note1[023456789acdefghjklmnpqrstuvwxyz]+)/g,
1014-
''
1015-
)
1016-
.replace(/\s+/g, ' ')
1017-
.trim();
1011+
return stripQuotedNoteReferences(content);
10181012
} catch {
10191013
return content || '';
10201014
}

src/lib/feed/noteContent.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { stripQuotedNoteReferences } from './noteContent';
3+
4+
const NEVENT =
5+
'nostr:nevent1qvzqqqqqqypzqvv660neqc6dh6r0zndec2v4kfhw833z30j4lzwycll2ntxqr4g2qy88wumn8ghj7mn0wvhxcmmv9uq3wamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet59uqzpwelkuhmeara2plp6xpapjk3m9hvzzsapqtfq2wmfjk6k7euzjdscjpx7f';
6+
7+
describe('stripQuotedNoteReferences', () => {
8+
it('preserves paragraphs and profile mentions when removing a quoted event', () => {
9+
const content =
10+
'What do you call a sauce recipe on nostr:npub1xxdd8eusvdxmaph3fkuu9x2mymhrcc3ghe2l38zv0l4f4nqp659qskkt7a? \n\nOpen sauce. 🍝\n' +
11+
NEVENT;
12+
13+
expect(stripQuotedNoteReferences(content)).toBe(
14+
'What do you call a sauce recipe on nostr:npub1xxdd8eusvdxmaph3fkuu9x2mymhrcc3ghe2l38zv0l4f4nqp659qskkt7a? \n\nOpen sauce. 🍝'
15+
);
16+
});
17+
18+
it('preserves line breaks after a leading quote reference', () => {
19+
expect(stripQuotedNoteReferences(`${NEVENT}\nFirst paragraph\n\nSecond paragraph`)).toBe(
20+
'First paragraph\n\nSecond paragraph'
21+
);
22+
});
23+
24+
it('removes note references without changing ordinary spacing', () => {
25+
const note = `nostr:note1${'q'.repeat(58)}`;
26+
27+
expect(stripQuotedNoteReferences(`Keep these words\n${note}`)).toBe('Keep these words');
28+
});
29+
});

src/lib/feed/noteContent.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const QUOTED_NOTE_REFERENCE =
2+
/nostr:(?:nevent1[023456789acdefghjklmnpqrstuvwxyz]+|note1[023456789acdefghjklmnpqrstuvwxyz]+)/g;
3+
4+
/** Remove embedded quote references without collapsing the author's line breaks. */
5+
export function stripQuotedNoteReferences(content: string): string {
6+
if (!content) return '';
7+
8+
return content.replace(QUOTED_NOTE_REFERENCE, '').trim();
9+
}

0 commit comments

Comments
 (0)