Skip to content

Commit b602ef3

Browse files
authored
feat: add wikilink to markdown link option (#102)
1 parent 3cd6a67 commit b602ef3

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface MarkdownExportPluginSettings {
2525
customFileName: string;
2626
customAttachPath: string;
2727
relAttachPath: boolean;
28+
convertWikiLinksToMarkdown: boolean;
2829
}
2930

3031
export const DEFAULT_SETTINGS: MarkdownExportPluginSettings = {
@@ -38,4 +39,5 @@ export const DEFAULT_SETTINGS: MarkdownExportPluginSettings = {
3839
customFileName: "",
3940
customAttachPath: "",
4041
relAttachPath: true,
42+
convertWikiLinksToMarkdown: false,
4143
};

src/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,18 @@ class MarkdownExportSettingTab extends PluginSettingTab {
266266
await this.plugin.saveSettings();
267267
})
268268
);
269+
new Setting(containerEl)
270+
.setName("Convert WikiLinks to Markdown")
271+
.setDesc(
272+
"Automatically convert WikiLink style links to Markdown links"
273+
)
274+
.addToggle((toggle) =>
275+
toggle
276+
.setValue(this.plugin.settings.convertWikiLinksToMarkdown)
277+
.onChange(async (value: boolean) => {
278+
this.plugin.settings.convertWikiLinksToMarkdown = value;
279+
await this.plugin.saveSettings();
280+
})
281+
);
269282
}
270283
}

src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ export async function tryCopyMarkdownByRead(
437437
content = content.replaceAll(OUTGOING_LINK_REGEXP, "$1");
438438
}
439439

440+
if (plugin.settings.convertWikiLinksToMarkdown) {
441+
content = content.replace(
442+
/\[\[(.*?)\]\]/g,
443+
(match, linkText) => {
444+
const encodedLink = encodeURIComponent(linkText);
445+
return `[${linkText}](${encodedLink})`;
446+
}
447+
);
448+
}
449+
440450
const cfile = plugin.app.workspace.getActiveFile();
441451
if (cfile != undefined) {
442452
const embedMap = await getEmbedMap(plugin, content, cfile.path);

0 commit comments

Comments
 (0)