@@ -234,17 +234,32 @@ const getFileLinkInFormat = (file: TFile, sourceFile: TFile, plugin: LinkConvert
234234
235235const  createLink  =  ( dest : LinkType ,  originalLink : string ,  altOrBlockRef : string ,  sourceFile : TFile ,  plugin : LinkConverterPlugin ) : string  =>  { 
236236    let  finalLink  =  originalLink ; 
237+     let  altText : string ; 
237238
238-     if  ( plugin . settings . finalLinkFormat  !==  'not-change' )  { 
239-         let  fileLink  =  decodeURI ( finalLink ) ; 
240-         let  file  =  plugin . app . metadataCache . getFirstLinkpathDest ( fileLink ,  sourceFile . path ) ; 
241-         if  ( file )  finalLink  =  getFileLinkInFormat ( file ,  sourceFile ,  plugin ,  plugin . settings . finalLinkFormat ) ; 
242-     } 
239+     let  fileLink  =  decodeURI ( finalLink ) ; 
240+     let  file  =  plugin . app . metadataCache . getFirstLinkpathDest ( fileLink ,  sourceFile . path ) ; 
241+     if  ( file  &&  plugin . settings . finalLinkFormat  !==  'not-change' )  finalLink  =  getFileLinkInFormat ( file ,  sourceFile ,  plugin ,  plugin . settings . finalLinkFormat ) ; 
243242
244243    if  ( dest  ===  'wiki' )  { 
245-         return  `[[${ decodeURI ( finalLink ) } ${ altOrBlockRef  !==  ''  &&  altOrBlockRef  !==  decodeURI ( finalLink )  ? '|'  +  altOrBlockRef  : '' }  ]]` ; 
244+         // If alt text is same as the final link or same as file base name, it needs to be empty 
245+         if  ( altOrBlockRef  !==  ''  &&  altOrBlockRef  !==  decodeURI ( finalLink ) )  { 
246+             if  ( file  &&  decodeURI ( altOrBlockRef )  ===  file . basename )  { 
247+                 altText  =  '' ; 
248+             }  else  { 
249+                 altText  =  '|'  +  altOrBlockRef ; 
250+             } 
251+         }  else  { 
252+             altText  =  '' ; 
253+         } 
254+         return  `[[${ decodeURI ( finalLink ) } ${ altText }  ]]` ; 
246255    }  else  if  ( dest  ===  'markdown' )  { 
247-         return  `[${ altOrBlockRef  !==  ''  ? altOrBlockRef  : finalLink }  ](${ encodeURI ( finalLink ) }  )` ; 
256+         // If there is no alt text specifiec and file exists, the alt text needs to be always the file base name 
257+         if  ( altOrBlockRef  !==  '' )  { 
258+             altText  =  altOrBlockRef ; 
259+         }  else  { 
260+             altText  =  file  ? file . basename  : finalLink ; 
261+         } 
262+         return  `[${ altText }  ](${ encodeURI ( finalLink ) }  )` ; 
248263    }  else  if  ( dest  ===  'wikiTransclusion' )  { 
249264        return  `[[${ decodeURI ( finalLink ) }  #${ decodeURI ( altOrBlockRef ) }  ]]` ; 
250265    }  else  if  ( dest  ===  'mdTransclusion' )  { 
0 commit comments