diff --git a/packages/foam-vscode/src/features/preview/wikilink-navigation.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-navigation.spec.ts index 1a6be695c..79e4ed16f 100644 --- a/packages/foam-vscode/src/features/preview/wikilink-navigation.spec.ts +++ b/packages/foam-vscode/src/features/preview/wikilink-navigation.spec.ts @@ -26,9 +26,9 @@ describe('Link generation in preview', () => { markdownItRemoveLinkReferences, ].reduce((acc, extension) => extension(acc, ws), MarkdownIt()); - it('generates a link to a note', () => { + it('generates a link to a note using the note title as link', () => { expect(md.render(`[[note-a]]`)).toEqual( - `
\n` + `\n` ); }); @@ -48,7 +48,7 @@ describe('Link generation in preview', () => { const note = `[[note-a]] [note-a]:note-a\n[note-a]: <note-a.md> "Note A"
\n` + `${noteA.title}\n[note-a]: <note-a.md> "Note A"
\n` ); }); @@ -63,7 +63,7 @@ describe('Link generation in preview', () => { it('generates a link to a note with a specific section', () => { expect(md.render(`[[note-b#sec2]]`)).toEqual( - `\n` + `\n` ); }); @@ -75,7 +75,7 @@ describe('Link generation in preview', () => { it('generates a link to a note if the note exists, but the section does not exist', () => { expect(md.render(`[[note-b#nonexistentsec]]`)).toEqual( - `\n` + `\n` ); }); diff --git a/packages/foam-vscode/src/features/preview/wikilink-navigation.ts b/packages/foam-vscode/src/features/preview/wikilink-navigation.ts index b02c656ca..b6ec7905c 100644 --- a/packages/foam-vscode/src/features/preview/wikilink-navigation.ts +++ b/packages/foam-vscode/src/features/preview/wikilink-navigation.ts @@ -42,13 +42,16 @@ export const markdownItWikilinkNavigation = ( return getPlaceholderLink(label); } + const resourceLabel = isEmpty(alias) + ? `${resource.title}${formattedSection}` + : alias; const resourceLink = `/${vscode.workspace.asRelativePath( toVsCodeUri(resource.uri) )}`; return getResourceLink( `${resource.title}${formattedSection}`, `${resourceLink}${linkSection}`, - label + resourceLabel ); } catch (e) { Logger.error(