From a62b869d0d5dfc764e4c73a61001d0646285b4f4 Mon Sep 17 00:00:00 2001 From: Paul de Raaij Date: Fri, 29 Oct 2021 16:29:24 +0200 Subject: [PATCH 1/2] Allow inclusion of note when using reference definitions --- packages/foam-vscode/src/features/preview-navigation.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/foam-vscode/src/features/preview-navigation.ts b/packages/foam-vscode/src/features/preview-navigation.ts index 5444ab8c7..04a1500c5 100644 --- a/packages/foam-vscode/src/features/preview-navigation.ts +++ b/packages/foam-vscode/src/features/preview-navigation.ts @@ -151,6 +151,11 @@ export const markdownItWithRemoveLinkReferences = ( if (refKey.includes(ALIAS_DIVIDER_CHAR)) { delete state.env.references[refKey]; } + + // if we try to include this note, we can remove the reference as well + if (state.src.toLowerCase().includes(`![[${refKey.toLowerCase()}]]`)) { + delete state.env.references[refKey]; + } }); } return false; From 4b3b275e5d1188ffc0c8ab8eb1f9fe922f832d9c Mon Sep 17 00:00:00 2001 From: Paul de Raaij Date: Thu, 4 Nov 2021 19:57:10 +0100 Subject: [PATCH 2/2] Add additional comments --- packages/foam-vscode/src/features/preview-navigation.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/foam-vscode/src/features/preview-navigation.ts b/packages/foam-vscode/src/features/preview-navigation.ts index 04a1500c5..d18089943 100644 --- a/packages/foam-vscode/src/features/preview-navigation.ts +++ b/packages/foam-vscode/src/features/preview-navigation.ts @@ -144,15 +144,19 @@ export const markdownItWithRemoveLinkReferences = ( md: markdownit, workspace: FoamWorkspace ) => { - // Forget about reference links that contain an alias divider md.inline.ruler.before('link', 'clear-references', state => { if (state.env.references) { Object.keys(state.env.references).forEach(refKey => { + // Forget about reference links that contain an alias divider + // Aliased reference links will lead the MarkdownParser to include wrong link references if (refKey.includes(ALIAS_DIVIDER_CHAR)) { delete state.env.references[refKey]; } - // if we try to include this note, we can remove the reference as well + // When the reference is present due to an inclusion of that note, we + // need to remove that reference. This ensures the MarkdownIt parser + // will not replace the wikilink syntax with an link and as a result + // break our inclusion logic. if (state.src.toLowerCase().includes(`![[${refKey.toLowerCase()}]]`)) { delete state.env.references[refKey]; }