-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnoteVariables.ts
More file actions
40 lines (36 loc) · 1.34 KB
/
noteVariables.ts
File metadata and controls
40 lines (36 loc) · 1.34 KB
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
import joplin from 'api';
import { ContentScriptType, MenuItemLocation } from 'api/types';
import { createVariablesNote } from './utils/createVariablesNote';
import { loadVariablesNotes } from './utils/loadVariablesNotes';
export namespace noteVariables {
/**
* Loads all the variables from the Notes into localStorage for the MD plugin
* @param e
*/
const onNoteChangeHandler = async (e: any) => {
if (e.event !== 2) return;
const note = await joplin.data.get(['notes', e.id], { fields: ['title'] });
if (note.title.match(/^\%[^%]*\%$/) == null) return;
loadVariablesNotes();
};
export async function init() {
await joplin.contentScripts.register(
ContentScriptType.MarkdownItPlugin,
'noteVariablesMD',
'./markdownItPlugin.js'
);
await joplin.workspace.onNoteChange(onNoteChangeHandler);
await joplin.workspace.onNoteSelectionChange(loadVariablesNotes);
await joplin.commands.register({
name: 'newVariablesNote',
label: 'Create variables note',
iconName: 'fas fa-superscript',
execute: async () => {
const folder = await joplin.workspace.selectedFolder();
createVariablesNote(folder.id);
},
});
await joplin.views.menuItems.create('Create variables vote', 'newVariablesNote', MenuItemLocation.Note);
await loadVariablesNotes();
}
}