File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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' ;
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 }
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 1+ const QUOTED_NOTE_REFERENCE =
2+ / n o s t r : (?: n e v e n t 1 [ 0 2 3 4 5 6 7 8 9 a c d e f g h j k l m n p q r s t u v w x y z ] + | n o t e 1 [ 0 2 3 4 5 6 7 8 9 a c d e f g h j k l m n p q r s t u v w x y z ] + ) / 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+ }
You can’t perform that action at this time.
0 commit comments