@@ -13,6 +13,9 @@ const UPLOAD_PATH_PATTERN =
1313const RELATIVE_UPLOAD_PATTERN =
1414 / ( ` + ) [ ^ ` ] * ?\1| ( \] \( \s * < ? | \b (?: s r c | h r e f ) \s * = \s * [ " ' ] ? | ^ { 0 , 3 } \[ [ ^ \] \n ] + \] : \s * < ? ) \/ u p l o a d s \/ (? = [ 0 - 9 a - f ] { 32 } \/ ) / giu;
1515const FENCE_PATTERN = / ^ \s { 0 , 3 } ( ` { 3 , } | ~ { 3 , } ) ( .* ) $ / u;
16+ /** A reference definition may put its destination on the next line. */
17+ const BARE_REFERENCE_LABEL_PATTERN = / ^ { 0 , 3 } \[ [ ^ \] \n ] + \] : \s * $ / u;
18+ const CONTINUED_UPLOAD_PATTERN = / ^ ( \s * < ? ) \/ u p l o a d s \/ (? = [ 0 - 9 a - f ] { 32 } \/ ) / u;
1619
1720export interface GitLabUpload {
1821 readonly origin : string ;
@@ -73,9 +76,12 @@ export function gitlabMediaFileName(fetchUrl: string): string {
7376export function resolveGitLabUploadLinks ( markdown : string , projectUrl : string ) : string {
7477 const base = projectUrl . replace ( / \/ + $ / u, "" ) ;
7578 let openFence : string | null = null ;
79+ let afterBareLabel = false ;
7680 return markdown
7781 . split ( "\n" )
7882 . map ( ( line ) => {
83+ const continuesLabel = afterBareLabel ;
84+ afterBareLabel = false ;
7985 const fence = FENCE_PATTERN . exec ( line ) ;
8086 if ( fence !== null ) {
8187 const marker = fence [ 1 ] ! ;
@@ -90,6 +96,12 @@ export function resolveGitLabUploadLinks(markdown: string, projectUrl: string):
9096 return line ;
9197 }
9298 if ( openFence !== null ) return line ;
99+ if ( continuesLabel ) {
100+ line = line . replace ( CONTINUED_UPLOAD_PATTERN , ( _match , prefix : string ) => {
101+ return `${ prefix } ${ base } /uploads/` ;
102+ } ) ;
103+ }
104+ afterBareLabel = BARE_REFERENCE_LABEL_PATTERN . test ( line ) ;
93105 return line . replace ( RELATIVE_UPLOAD_PATTERN , ( match , _code , prefix : string | undefined ) =>
94106 prefix === undefined ? match : `${ prefix } ${ base } /uploads/` ,
95107 ) ;
0 commit comments