Skip to content

Commit

Permalink
Fixed folders for markdown links
Browse files Browse the repository at this point in the history
  • Loading branch information
natefrisch01 committed Jan 10, 2024
1 parent b6a8d03 commit f6a1f8b
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 6 deletions.
10 changes: 8 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Plugin, WorkspaceLeaf, Notice} from 'obsidian';
import { getAPI, Page } from 'obsidian-dataview';
import * as PIXI from 'pixi.js';
import extractLinks from 'markdown-link-extractor';

export default class GraphLinkTypesPlugin extends Plugin {
// Retrieve the Dataview API
Expand Down Expand Up @@ -272,6 +273,7 @@ export default class GraphLinkTypesPlugin extends Plugin {
break;
case LinkType.MarkdownLink:
if (this.extractPathFromMarkdownLink(value) === targetId) {
console.log(targetId);
return key;
}
break;
Expand All @@ -281,6 +283,7 @@ export default class GraphLinkTypesPlugin extends Plugin {
return key;
}
if (this.determineLinkType(item) === LinkType.MarkdownLink && this.extractPathFromMarkdownLink(item) === targetId) {
console.log(targetId);
return key;
}
}
Expand All @@ -293,10 +296,13 @@ export default class GraphLinkTypesPlugin extends Plugin {

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


// Utility function to check if a value is a Markdown link
isMarkdownLink(value: any, targetId: string): boolean {
if (typeof value === 'string') {
Expand Down
218 changes: 214 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"typescript": "4.7.4"
},
"dependencies": {
"markdown-link-extractor": "^3.1.0",
"pixi.js": "^7.3.3"
}
}

0 comments on commit f6a1f8b

Please sign in to comment.