Foam: Autogenerated links not creating

Created on 7 Nov 2020  路  6Comments  路  Source: foambubble/foam

Describe the bug
I used to have the ability to change the way my autogenerated links were displayed. For example, I have a page edmun-gettier. I could link it by going [[Edmund Gettier]] and it would show up in the autogenerated section. However, I noticed this isn't happening anymore.

Is this just something I've broken on my end?

Affected package

  • [ ] foam-cli
  • [ ] foam-core
  • [x] foam-vscode
  • [ ] other/meta/???

To Reproduce

I expect to see:

[//begin]: # "Autogenerated link references for markdown compatibility"
[phil-1101]: phil-1101 "PHIL 1101 - Intro to Philosophy: Knowledge and Reality"
[edmund-gettier]: edmund-gettier "Edmund Gettier"
[//end]: # "Autogenerated link references"

Screenshots

image

Here is an example of a previous one that worked:
image

Additional context

bug

All 6 comments

Encountering the same issue after upgrading to v0.4 and still present with v0.5. My guess is that foam isn't normalizing the link text via the slugger before checking if the file exists. Should be easy enough to check with a dev setup.

I looked into this, and found out that for wikilinks in the markdown that are not slugged, they are passed as it is. This was happening because the wikiLinks plugin visit did not slugify the links that are found. Here's the diff:

diff --git a/packages/foam-core/src/markdown-provider.ts b/packages/foam-core/src/markdown-provider.ts
index af997aa..a65053a 100644
--- a/packages/foam-core/src/markdown-provider.ts
+++ b/packages/foam-core/src/markdown-provider.ts
@@ -13,6 +13,7 @@ import {
   uriToSlug,
   extractHashtags,
   extractTagsFromProp,
+  nameToSlug,
 } from './utils';
 import { ID } from './types';
 import { ParserPlugin } from './plugins';
@@ -53,7 +54,7 @@ const wikilinkPlugin: ParserPlugin = {
     if (node.type === 'wikiLink') {
       note.links.push({
         type: 'wikilink',
-        slug: node.value as string,
+        slug: nameToSlug(node.value) as string,
         position: node.position!,
       });
     }
diff --git a/packages/foam-core/src/utils/uri.ts b/packages/foam-core/src/utils/uri.ts
index 8a98925..ed158bc 100644
--- a/packages/foam-core/src/utils/uri.ts
+++ b/packages/foam-core/src/utils/uri.ts
@@ -7,6 +7,10 @@ export const uriToSlug = (noteUri: URI): string => {
   return GithubSlugger.slug(path.parse(noteUri).name);
 };

+export const nameToSlug = (noteName: any): string => {
+  return GithubSlugger.slug(noteName);
+};

Let me know if this will have any corner cases to look into, or I will open a PR soon.

I think there is some option which slugger to use somewhere, but I might be confusing that with another plugin. So it might be necessary to look up the configured slugging method somewhere for it to be consistent. In any case, I would greatly appreciate you opening a PR with this patch already, makes it easier for someone to run and test, and then potentially report issues with corner cases.

@SanketDG @fmagin the way linking works will be part of a major update soon.

Basically what you are saying is correct, but we don't want to limit support to slugs.
I would like to simply use file names, paths to disambiguate, and manage other cases (e.g. link definition generation) from there.
E.g. I think the problem here is that the field shouldn't be called slug, but be more generic.

The approach is not fully flushed, so if you have any thoughts please do share :)

Would it be possible to add @SanketDG's fix to a version 0.5.1? I still consider this a fairly annoying regression which breaks various things like the Markdown Graph integration and links in the preview. The Foam Graph has other issues with missing edges (that might also be alleviated with this). For me it would only be annoying to build my own extension version with this patch, but I also recommended Foam to someone who can't reasonably do that, and they are now on version 0.5 that basically works significantly worse than 0.3 :/

@fmagin I am happy to implement a fix for the regression while the details for the link specs are being defined.

After some research I think I understand the source of the problem, it's in commit https://github.com/foambubble/foam/commit/87f172d217a88a6e46cd8dc4006bea0609c2ece6

Reviewing the tests (which are passing) I see that [[Example with title]] was not a test case - we can add that. Probably this is why the issue had not been caught (to be honest, I never used it that way, so I didn't notice it on my machine)

@SanketDG yes please, open a PR with the fix and a the test case for it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsjoeio picture jsjoeio  路  3Comments

WoutV picture WoutV  路  5Comments

Josh2K picture Josh2K  路  3Comments

SpaceForever picture SpaceForever  路  6Comments

sahil48 picture sahil48  路  3Comments