Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8: Allow internal links #13

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ export default class Linkify extends Plugin {
evt.target.className.includes("cm-link linkified")) {
let m = this.matchRule(evt.target.innerText);
if (m != null) {
window.open(m.link);
// try to match internal link
const internalLinkMatch = m.link.match(/^\[\[([^|\]]*)(?:\|[^|\]]*)?\]\]$/);
if (internalLinkMatch != null) {
this.app.workspace.openLinkText(internalLinkMatch.at(1), "");
} else {
window.open(m.link);
}
}
}
}
Expand Down Expand Up @@ -149,8 +155,7 @@ export default class Linkify extends Plugin {
// Converts matching text in the HTMLElement into links.
markdownPostProcessor(el: HTMLElement) {
if (el.firstChild instanceof Node) {
let walker = document.createTreeWalker(
el.firstChild, NodeFilter.SHOW_TEXT, null);
let walker = document.createTreeWalker(el.firstChild, NodeFilter.SHOW_TEXT, null);
let nodes: Node[] = [];
let node: Node;
while (node = walker.nextNode()) {
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "linkify",
"version": "1.0.13",
"description": "Turns strings into links.",
"main": "main.js",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
Expand All @@ -12,13 +12,13 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"builtin-modules": "^3.2.0",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"builtin-modules": "^3.3.0",
"esbuild": "0.13.12",
"obsidian": "latest",
"tslib": "2.3.1",
"typescript": "4.4.4"
"tslib": "2.6.2",
"typescript": "5.3.3"
}
}