mirror of
https://github.com/kovah/obsidian-jira-auto-linker.git
synced 2026-07-22 06:45:27 +00:00
Minor corrections after plugin review
This commit is contained in:
parent
41cbedfbf4
commit
eeeae91e85
5 changed files with 37 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import builtins from 'builtin-modules';
|
||||
import esbuild from 'esbuild';
|
||||
import { sassPlugin } from 'esbuild-sass-plugin';
|
||||
import { builtinModules } from 'node:module';
|
||||
import process from 'process';
|
||||
|
||||
const banner =
|
||||
|
|
@ -35,7 +35,7 @@ const context = await esbuild.context({
|
|||
'@lezer/common',
|
||||
'@lezer/highlight',
|
||||
'@lezer/lr',
|
||||
...builtins
|
||||
...builtinModules
|
||||
],
|
||||
format: 'cjs',
|
||||
target: 'es2018',
|
||||
|
|
|
|||
33
main.ts
33
main.ts
|
|
@ -20,6 +20,28 @@ const DEFAULT_SETTINGS: JiraAutoLinkerSettings = {
|
|||
registrations: [],
|
||||
};
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null;
|
||||
}
|
||||
|
||||
function isJiraProjectRegistration(value: unknown): value is JiraProjectRegistration {
|
||||
return isRecord(value)
|
||||
&& typeof value.projectKey === 'string'
|
||||
&& typeof value.baseUrl === 'string';
|
||||
}
|
||||
|
||||
function normalizeSettings(data: unknown): JiraAutoLinkerSettings {
|
||||
if (!isRecord(data) || !Array.isArray(data.registrations)) {
|
||||
return {
|
||||
registrations: [...DEFAULT_SETTINGS.registrations],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
registrations: data.registrations.filter(isJiraProjectRegistration),
|
||||
};
|
||||
}
|
||||
|
||||
export default class JiraAutoLinker extends Plugin {
|
||||
settings: JiraAutoLinkerSettings;
|
||||
|
||||
|
|
@ -87,15 +109,15 @@ export default class JiraAutoLinker extends Plugin {
|
|||
}
|
||||
|
||||
private replaceWithLinks(node: Node, text: string, matches: Array<JiraLinkMatch>) {
|
||||
const fragment = document.createDocumentFragment();
|
||||
const fragment = createFragment();
|
||||
let cursor = 0;
|
||||
|
||||
for (const match of matches) {
|
||||
if (match.start > cursor) {
|
||||
fragment.appendChild(document.createTextNode(text.substring(cursor, match.start)));
|
||||
fragment.appendChild(activeDocument.createTextNode(text.substring(cursor, match.start)));
|
||||
}
|
||||
|
||||
const anchor = document.createElement('a');
|
||||
const anchor = activeDocument.createElement('a');
|
||||
anchor.textContent = match.matchedText;
|
||||
anchor.href = `${match.registration.baseUrl}/browse/${match.matchedText}`;
|
||||
anchor.target = '_blank';
|
||||
|
|
@ -105,7 +127,7 @@ export default class JiraAutoLinker extends Plugin {
|
|||
}
|
||||
|
||||
if (cursor < text.length) {
|
||||
fragment.appendChild(document.createTextNode(text.substring(cursor)));
|
||||
fragment.appendChild(activeDocument.createTextNode(text.substring(cursor)));
|
||||
}
|
||||
|
||||
node.parentNode?.replaceChild(fragment, node);
|
||||
|
|
@ -116,7 +138,8 @@ export default class JiraAutoLinker extends Plugin {
|
|||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
const data: unknown = await this.loadData();
|
||||
this.settings = normalizeSettings(data);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "atlassian-jira-auto-linker",
|
||||
"name": "Atlassian Jira Auto-Linker",
|
||||
"version": "1.0.1",
|
||||
"minAppVersion": "1.0.0",
|
||||
"minAppVersion": "1.1.0",
|
||||
"description": "Automatically create links to Jira from issue IDs like APP-1426.",
|
||||
"author": "Kevin Woblick",
|
||||
"authorUrl": "https://woblick.dev",
|
||||
|
|
@ -12,4 +12,4 @@
|
|||
"Liberapay": "https://liberapay.com/kovah"
|
||||
},
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
package-lock.json
generated
24
package-lock.json
generated
|
|
@ -9,15 +9,14 @@
|
|||
"version": "1.0.1",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.4",
|
||||
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
||||
"@typescript-eslint/parser": "^8.24.0",
|
||||
"builtin-modules": "^4.0.0",
|
||||
"esbuild": "^0.25.0",
|
||||
"@types/node": "^22.13.10",
|
||||
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
||||
"@typescript-eslint/parser": "^8.26.1",
|
||||
"esbuild": "^0.25.1",
|
||||
"esbuild-sass-plugin": "^3.3.1",
|
||||
"obsidian": "latest",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.3"
|
||||
"typescript": "^5.8.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@bufbuild/protobuf": {
|
||||
|
|
@ -1492,19 +1491,6 @@
|
|||
"license": "MIT/X11",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/builtin-modules": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-4.0.0.tgz",
|
||||
"integrity": "sha512-p1n8zyCkt1BVrKNFymOHjcDSAl7oq/gUvfgULv2EblgpPVQlQr9yHnWjg9IJ2MhfwPqiYqMMrr01OY7yQoK2yA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.20"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
"@types/node": "^22.13.10",
|
||||
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
||||
"@typescript-eslint/parser": "^8.26.1",
|
||||
"builtin-modules": "^4.0.0",
|
||||
"esbuild": "^0.25.1",
|
||||
"esbuild-sass-plugin": "^3.3.1",
|
||||
"obsidian": "latest",
|
||||
|
|
|
|||
Loading…
Reference in a new issue