@@ -37,7 +37,6 @@ function loadFont(): { data: Buffer; name: string; weight: 400; style: 'normal'
3737 * Extracts a window of text around the first change for the card.
3838 */
3939function parseDiffToElements ( diffHtml : string , maxLength : number = 600 ) : any [ ] {
40- // Strip the wrapper divs
4140 const html = diffHtml
4241 . replace ( / < d i v c l a s s = " d i f f - (?: t i t l e | c o n t e n t ) " > / g, '' )
4342 . replace ( / < \/ d i v > / g, '' )
@@ -46,7 +45,6 @@ function parseDiffToElements(diffHtml: string, maxLength: number = 600): any[] {
4645 . replace ( / & g t ; / g, '>' )
4746 . replace ( / & q u o t ; / g, '"' ) ;
4847
49- // Parse into segments: text, <ins>...</ins>, <del>...</del>
5048 const segments : { type : 'text' | 'ins' | 'del' ; value : string } [ ] = [ ] ;
5149 const regex = / < ( i n s | d e l ) > ( .* ?) < \/ \1> / gs;
5250 let lastIndex = 0 ;
@@ -62,16 +60,26 @@ function parseDiffToElements(diffHtml: string, maxLength: number = 600): any[] {
6260 segments . push ( { type : 'text' , value : html . slice ( lastIndex ) } ) ;
6361 }
6462
65- // Find the first change and build a window around it
6663 const firstChangeIdx = segments . findIndex ( s => s . type !== 'text' ) ;
6764 if ( firstChangeIdx === - 1 ) return [ { type : 'span' , props : { children : '(no visible changes)' } } ] ;
6865
69- // Collect segments around the first change, respecting maxLength
70- let totalLen = 0 ;
71- const start = Math . max ( 0 , firstChangeIdx - 1 ) ;
66+ // Show brief context (max 80 chars) before the change, then prioritize the diff content
67+ const contextMax = 80 ;
7268 const windowSegments : typeof segments = [ ] ;
69+ let totalLen = 0 ;
70+
71+ // Add brief leading context
72+ if ( firstChangeIdx > 0 ) {
73+ const leadText = segments [ firstChangeIdx - 1 ] . value ;
74+ const context = leadText . length > contextMax
75+ ? '...' + leadText . slice ( - contextMax )
76+ : leadText ;
77+ windowSegments . push ( { type : 'text' , value : context } ) ;
78+ totalLen += context . length ;
79+ }
7380
74- for ( let i = start ; i < segments . length && totalLen < maxLength ; i ++ ) {
81+ // Fill the rest with change segments and their surrounding text
82+ for ( let i = firstChangeIdx ; i < segments . length && totalLen < maxLength ; i ++ ) {
7583 const remaining = maxLength - totalLen ;
7684 const seg = { ...segments [ i ] } ;
7785 if ( seg . value . length > remaining ) {
@@ -81,25 +89,17 @@ function parseDiffToElements(diffHtml: string, maxLength: number = 600): any[] {
8189 totalLen += seg . value . length ;
8290 }
8391
84- // If we skipped leading context, prepend ellipsis
85- if ( start > 0 ) {
86- const leadText = segments [ start - 1 ] ?. value || '' ;
87- const tail = leadText . slice ( - 80 ) ;
88- if ( tail ) {
89- windowSegments . unshift ( { type : 'text' , value : '...' + tail } ) ;
90- }
91- }
92-
9392 return windowSegments . map ( ( seg ) => {
9493 if ( seg . type === 'ins' ) {
9594 return {
9695 type : 'span' ,
9796 props : {
9897 style : {
99- backgroundColor : '#d4edda' ,
100- color : '#155724' ,
101- padding : '1px 3px' ,
102- borderRadius : '2px'
98+ backgroundColor : '#bbf7d0' ,
99+ color : '#14532d' ,
100+ padding : '2px 4px' ,
101+ borderRadius : '3px' ,
102+ fontWeight : '600'
103103 } ,
104104 children : seg . value
105105 }
@@ -110,17 +110,17 @@ function parseDiffToElements(diffHtml: string, maxLength: number = 600): any[] {
110110 type : 'span' ,
111111 props : {
112112 style : {
113- backgroundColor : '#f8d7da ' ,
114- color : '#721c24 ' ,
113+ backgroundColor : '#fecaca ' ,
114+ color : '#7f1d1d ' ,
115115 textDecoration : 'line-through' ,
116- padding : '1px 3px ' ,
117- borderRadius : '2px '
116+ padding : '2px 4px ' ,
117+ borderRadius : '3px '
118118 } ,
119119 children : seg . value
120120 }
121121 } ;
122122 }
123- return { type : 'span' , props : { children : seg . value } } ;
123+ return { type : 'span' , props : { style : { color : '#6b7280' } , children : seg . value } } ;
124124 } ) ;
125125}
126126
0 commit comments