Skip to content

Commit f6a1f8b

Browse files
committed
Fixed folders for markdown links
1 parent b6a8d03 commit f6a1f8b

File tree

3 files changed

+223
-6
lines changed

3 files changed

+223
-6
lines changed

main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Plugin, WorkspaceLeaf, Notice} from 'obsidian';
22
import { getAPI, Page } from 'obsidian-dataview';
33
import * as PIXI from 'pixi.js';
4+
import extractLinks from 'markdown-link-extractor';
45

56
export default class GraphLinkTypesPlugin extends Plugin {
67
// Retrieve the Dataview API
@@ -272,6 +273,7 @@ export default class GraphLinkTypesPlugin extends Plugin {
272273
break;
273274
case LinkType.MarkdownLink:
274275
if (this.extractPathFromMarkdownLink(value) === targetId) {
276+
console.log(targetId);
275277
return key;
276278
}
277279
break;
@@ -281,6 +283,7 @@ export default class GraphLinkTypesPlugin extends Plugin {
281283
return key;
282284
}
283285
if (this.determineLinkType(item) === LinkType.MarkdownLink && this.extractPathFromMarkdownLink(item) === targetId) {
286+
console.log(targetId);
284287
return key;
285288
}
286289
}
@@ -293,10 +296,13 @@ export default class GraphLinkTypesPlugin extends Plugin {
293296

294297
// Utility function to extract the file path from a Markdown link
295298
private extractPathFromMarkdownLink(markdownLink: string): string {
296-
const match = markdownLink.match(/\[.*\]\((.*?)\)/);
297-
return match ? match[1] : '';
299+
const links = extractLinks(markdownLink).links;
300+
console.log(links[0]);
301+
// The package returns an array of links. Assuming you want the first link.
302+
return links.length > 0 ? links[0] : '';
298303
}
299304

305+
300306
// Utility function to check if a value is a Markdown link
301307
isMarkdownLink(value: any, targetId: string): boolean {
302308
if (typeof value === 'string') {

package-lock.json

Lines changed: 214 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"typescript": "4.7.4"
2424
},
2525
"dependencies": {
26+
"markdown-link-extractor": "^3.1.0",
2627
"pixi.js": "^7.3.3"
2728
}
2829
}

0 commit comments

Comments
 (0)