generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
88 lines (80 loc) · 2.05 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Plugin, Notice } from 'obsidian';
import { openBibTeXModal } from './interface';
import { processBibTeX } from './processBibTeX';
export interface Reference {
citeKey: string;
title: string;
author: string;
editor?: string;
year: number;
publisher?: string;
journal?: string;
volume?: string;
number?: string;
pages?: string;
booktitle?: string;
address?: string;
month?: string;
note?: string;
doi?: string;
url?: string;
isbn?: string;
issn?: string;
abstract?: string;
eprint?: string;
}
export interface Author {
name: string;
}
export interface BibTeXData {
references: Reference[];
authors: Author[];
}
export interface BibTeXEntryData {
title?: string;
author?: string;
editor?: string;
year?: string;
publisher?: string;
journal?: string;
volume?: string;
number?: string;
pages?: string;
booktitle?: string;
address?: string;
month?: string;
note?: string;
doi?: string;
url?: string;
isbn?: string;
issn?: string;
abstract?: string;
eprint?: string;
}
export default class BibTeXProcessorPlugin extends Plugin {
async onload() {
console.log('BibTeX plugin loaded');
// Add ribbon icon
this.addRibbonIcon('book-open-check', 'Process BibTeX', async () => {
const bibtexData = await openBibTeXModal();
if (bibtexData) {
await processBibTeX(bibtexData);
} else {
new Notice('Failed to get BibTeX data.');
}
});
// Register command for command palette
this.addCommand({
id: 'process-bibtex',
name: 'Process BibTeX',
callback: async () => {
const bibtexData = await openBibTeXModal();
if (bibtexData) {
await processBibTeX(bibtexData);
} else {
new Notice('Failed to get BibTeX data.');
}
},
});
}
}