generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
61 lines (48 loc) · 1.43 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
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
// @ts-ignore
import create from "typograms/src/typograms.js";
interface TextgramsSettings {
zoom: string;
}
const DEFAULT_SETTINGS: TextgramsSettings = {
zoom: "1"
}
export default class Textgrams extends Plugin {
settings: TextgramsSettings;
async onload() {
await this.loadSettings();
this.registerMarkdownCodeBlockProcessor("textgram", (source, el, ctx) => {
const svg = create("\n" + source + "\n", +this.settings.zoom, false);
el.addClass("textgram");
el.appendChild(svg);
});
this.addSettingTab(new TextgramsSettingTab(this.app, this));
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
class TextgramsSettingTab extends PluginSettingTab {
plugin: Textgrams;
constructor(app: App, plugin: Textgrams) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Zoom level')
.setDesc('Zoom level for textgrams. Default is 1 and it works best for most cases.')
.addText(text => text
.setPlaceholder('Default: 1')
.setValue(this.plugin.settings.zoom)
.onChange(async (value) => {
this.plugin.settings.zoom = value;
await this.plugin.saveSettings();
}));
}
}