forked from artisticat1/nl-syntax-highlighting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
220 lines (172 loc) · 5.85 KB
/
settings.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { App, PluginSettingTab, Setting, debounce } from 'obsidian';
import NLSyntaxHighlightPlugin from 'main';
export interface NLSyntaxHighlightPluginSettings {
adjectiveEnabled: boolean,
adjectiveColor: string,
nounEnabled: boolean,
nounColor: string,
adverbEnabled: boolean,
adverbColor: string,
verbEnabled: boolean,
verbColor: string,
conjunctionEnabled: boolean,
conjunctionColor: string,
classToApplyHighlightingTo: string,
wordsToOverride: string,
}
export const DEFAULT_SETTINGS: NLSyntaxHighlightPluginSettings = {
adjectiveEnabled: true,
adjectiveColor: "#b97a0a",
nounEnabled: true,
nounColor: "#ce4924",
adverbEnabled: true,
adverbColor: "#c333a7",
verbEnabled: true,
verbColor: "#177eB8",
conjunctionEnabled: true,
conjunctionColor: "#01934e",
classToApplyHighlightingTo: "",
wordsToOverride: "",
}
export class NLSyntaxHighlightSettingTab extends PluginSettingTab {
plugin: NLSyntaxHighlightPlugin;
constructor(app: App, plugin: NLSyntaxHighlightPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
const adjectives = new Setting(containerEl).setName("Adjectives");
let adjectiveToggle:HTMLElement;
adjectives.addToggle(toggle =>
{
adjectiveToggle = toggle.toggleEl;
adjectiveToggle.parentElement?.parentElement?.prepend(adjectiveToggle);
toggle.setValue(this.plugin.settings.adjectiveEnabled)
.onChange(async (value) => {
this.plugin.settings.adjectiveEnabled = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
})
}
);
adjectives.addColorPicker(component => component
.setValue(this.plugin.settings.adjectiveColor)
.onChange(async (value) => {
this.plugin.settings.adjectiveColor = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
const nouns = new Setting(containerEl).setName("Nouns");
let nounToggle:HTMLElement;
nouns.addToggle(toggle =>
{
nounToggle = toggle.toggleEl;
nounToggle.parentElement?.parentElement?.prepend(nounToggle);
toggle.setValue(this.plugin.settings.nounEnabled)
.onChange(async (value) => {
this.plugin.settings.nounEnabled = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
})
}
);
nouns.addColorPicker(component => component
.setValue(this.plugin.settings.nounColor)
.onChange(async (value) => {
this.plugin.settings.nounColor = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
const adverbs = new Setting(containerEl).setName("Adverbs");
let adverbToggle:HTMLElement;
adverbs.addToggle(toggle =>
{
adverbToggle = toggle.toggleEl;
adverbToggle.parentElement?.parentElement?.prepend(adverbToggle);
toggle.setValue(this.plugin.settings.adverbEnabled)
.onChange(async (value) => {
this.plugin.settings.adverbEnabled = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
})
}
);
adverbs.addColorPicker(component => component
.setValue(this.plugin.settings.adverbColor)
.onChange(async (value) => {
this.plugin.settings.adverbColor = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
const verbs = new Setting(containerEl).setName("Verbs");
let verbToggle:HTMLElement;
verbs.addToggle(toggle =>
{
verbToggle = toggle.toggleEl;
verbToggle.parentElement?.parentElement?.prepend(verbToggle);
toggle.setValue(this.plugin.settings.verbEnabled)
.onChange(async (value) => {
this.plugin.settings.verbEnabled = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
})
}
);
verbs.addColorPicker(component => component
.setValue(this.plugin.settings.verbColor)
.onChange(async (value) => {
this.plugin.settings.verbColor = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
const conjunctions = new Setting(containerEl).setName("Conjunctions");
let conjunctionToggle:HTMLElement;
conjunctions.addToggle(toggle =>
{
conjunctionToggle = toggle.toggleEl;
conjunctionToggle.parentElement?.parentElement?.prepend(conjunctionToggle);
toggle.setValue(this.plugin.settings.conjunctionEnabled)
.onChange(async (value) => {
this.plugin.settings.conjunctionEnabled = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
})
}
);
conjunctions.addColorPicker(component => component
.setValue(this.plugin.settings.conjunctionColor)
.onChange(async (value) => {
this.plugin.settings.conjunctionColor = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
new Setting(containerEl)
.setName('Words to override')
.setDesc('Occasionally, words may be misclassfied. Type words here to override their classification. Use the format word: part-of-speech, with each word separated by a new line. e.g. snowy: adjective')
.addTextArea(text => text
.setValue(this.plugin.settings.wordsToOverride)
.setPlaceholder(`snowy: adjective
cloud: noun`)
.onChange(async (value) => {
this.plugin.settings.wordsToOverride = value;
this.plugin.loadWordsToOverrideDict();
this.plugin.reloadEditorExtensions();
debounce(() => {
this.plugin.reloadEditorExtensions();
}, 1000);
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('CSS class to apply syntax highlighting to')
.setDesc('If specified, the syntax highlighting will only be applied to notes with the "cssclass" property in their YAML equal to the specified value.')
.addText(text => text
.setValue(this.plugin.settings.classToApplyHighlightingTo)
.onChange(async (value) => {
this.plugin.settings.classToApplyHighlightingTo = value;
await this.plugin.saveSettings();
this.plugin.reloadStyle();
}));
}
}