Skip to content

Commit d368f61

Browse files
author
Ozan Tellioglu
committed
#7 Markdown Format Extension Included
1 parent 1b9762a commit d368f61

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/converter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ const createLink = (dest: LinkType, originalLink: string, altOrBlockRef: string,
271271
let file = plugin.app.metadataCache.getFirstLinkpathDest(fileLink, sourceFile.path);
272272
if (file && plugin.settings.finalLinkFormat !== 'not-change') finalLink = getFileLinkInFormat(file, sourceFile, plugin, plugin.settings.finalLinkFormat);
273273

274+
// If final link is in markdown format and the file is md, the extension should be included
275+
const fileExtension = file && file.extension === 'md' ? `.${file.extension}` : '';
276+
274277
if (dest === 'wiki') {
275278
// If alt text is same as the final link or same as file base name, it needs to be empty
276279
if (altOrBlockRef !== '' && altOrBlockRef !== decodeURI(finalLink)) {
@@ -290,7 +293,7 @@ const createLink = (dest: LinkType, originalLink: string, altOrBlockRef: string,
290293
} else {
291294
altText = file ? file.basename : finalLink;
292295
}
293-
return `[${altText}](${encodeURI(finalLink)})`;
296+
return `[${altText}](${encodeURI(finalLink)}${fileExtension})`;
294297
} else if (dest === 'wikiTransclusion') {
295298
return `[[${decodeURI(finalLink)}#${decodeURI(altOrBlockRef)}]]`;
296299
} else if (dest === 'mdTransclusion') {
@@ -302,7 +305,7 @@ const createLink = (dest: LinkType, originalLink: string, altOrBlockRef: string,
302305
} else {
303306
encodedBlockRef = encodeURI(encodedBlockRef);
304307
}
305-
return `[](${encodeURI(finalLink)}#${encodedBlockRef})`;
308+
return `[](${encodeURI(finalLink)}${fileExtension}#${encodedBlockRef})`;
306309
}
307310

308311
return '';

0 commit comments

Comments
 (0)