File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export interface MarkdownExportPluginSettings {
2525 customFileName : string ;
2626 customAttachPath : string ;
2727 relAttachPath : boolean ;
28+ convertWikiLinksToMarkdown : boolean ;
2829}
2930
3031export const DEFAULT_SETTINGS : MarkdownExportPluginSettings = {
@@ -38,4 +39,5 @@ export const DEFAULT_SETTINGS: MarkdownExportPluginSettings = {
3839 customFileName : "" ,
3940 customAttachPath : "" ,
4041 relAttachPath : true ,
42+ convertWikiLinksToMarkdown : false ,
4143} ;
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments