From 51b1af19819d9601abc64a29e6fa11eea9a2837b Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 30 Nov 2023 19:17:50 +0100 Subject: [PATCH] Using note title in preview panel (#1309) See conversation in https://github.com/foambubble/foam/pull/1150 --- .../src/features/preview/wikilink-navigation.spec.ts | 10 +++++----- .../src/features/preview/wikilink-navigation.ts | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) 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( - `

note-a

\n` + `

${noteA.title}

\n` ); }); @@ -48,7 +48,7 @@ describe('Link generation in preview', () => { const note = `[[note-a]] [note-a]: "Note A"`; expect(md.render(note)).toEqual( - `

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( - `

note-b#sec2

\n` + `

${noteB.title}#sec2

\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( - `

note-b#nonexistentsec

\n` + `

${noteB.title}#nonexistentsec

\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(