@@ -2,13 +2,16 @@ import { regex } from '../regex.js';
22import { template } from '../template.js' ;
33import { url } from '../url.js' ;
44export const commitCompact = ( text , repo ) => {
5- const replacer = ( value , item ) => value . replace ( item [ 0 ] , template ( 'commit' , `${ item [ 1 ] } /${ item [ 2 ] } ` , item [ 3 ] ) ) ;
6- text = regex ( text , / \[ [ \w \d \s ` ] + ] \( h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w \d \- _ ] + ) \/ ( [ \w \d \- _ ] + ) \/ c o m m i t \/ ( [ \w \d ] { 40 } ) \) / g, replacer ) ;
7- text = regex ( text , / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w \d \- _ ] + ) \/ ( [ \w \d \- _ ] + ) \/ c o m m i t \/ ( [ \w \d ] { 40 } ) / g, replacer ) ;
5+ const replacerFull = ( value , item ) => value . replace ( item [ 0 ] , template ( 'commit' , `${ item [ 1 ] } /${ item [ 2 ] } ` , item [ 3 ] ) ) ;
6+ const replacerShort = ( value , item ) => value . replace ( item [ 0 ] , template ( 'commit' , repo , item [ 1 ] ) ) ;
7+ text = regex ( text , / < a .* h r e f \s ? = \s ? " ? h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w \d \- _ ] + ) \/ ( [ \w \d \- _ ] + ) \/ c o m m i t \/ ( [ \w \d ] { 40 } ) " ? .* > .* < \/ a > / g, replacerFull ) ;
8+ text = regex ( text , / \[ [ \w \d \s ` ] + ] \( h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w \d \- _ ] + ) \/ ( [ \w \d \- _ ] + ) \/ c o m m i t \/ ( [ \w \d ] { 40 } ) \) / g, replacerFull ) ;
9+ text = regex ( text , / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w \d \- _ ] + ) \/ ( [ \w \d \- _ ] + ) \/ c o m m i t \/ ( [ \w \d ] { 40 } ) / g, replacerFull ) ;
10+ text = regex ( text , / [ ^ \D \W \S : ] * ( [ \w \d ] { 40 } ) [ ^ : ] / g, replacerShort ) ;
811 return text ;
912} ;
1013export const commitExpand = ( text , repo ) => {
11- const replacer = ( value , item ) => value . replace ( item [ 0 ] , url ( `${ item [ 1 ] } # ${ item [ 2 ] . substring ( 0 , 7 ) } ` , `${ item [ 1 ] } /commit/${ item [ 2 ] } ` ) ) ;
14+ const replacer = ( value , item ) => value . replace ( item [ 0 ] , url ( repo , `${ item [ 1 ] . includes ( repo ) ? '' : item [ 1 ] + '#' } ${ item [ 2 ] . substring ( 0 , 7 ) } ` , `${ item [ 1 ] } /commit/${ item [ 2 ] } ` ) ) ;
1215 text = regex ( text , / : : c o m m i t : : ( [ \w \d \- _ \/ ] + ) : : ( [ \w \d ] + ) : : / g, replacer ) ;
1316 return text ;
1417} ;
0 commit comments