-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
executable file
·60 lines (50 loc) · 1.42 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
import { Plugin } from 'obsidian';
import {
getMountContext,
MountContext,
mountEnhancedTables,
} from 'src/utils/mount';
import { TableManager } from 'src/TableManager';
function isError(possibleMountContext: any): possibleMountContext is string {
return typeof possibleMountContext === 'string';
}
export default class EnhancedTablesPlugin extends Plugin {
public tableManager = new TableManager();
async onload() {
this.registerMarkdownPostProcessor(async (el, ctx) => {
const possibleMountContext = await getMountContext(el, ctx);
if (!possibleMountContext) {
return;
}
if (isError(possibleMountContext)) {
const errorsContainer = el.createDiv({ cls: 'enhanced-tables-errors' });
errorsContainer.createDiv({
text: `⚠️ Validation errors:`,
cls: 'enhanced-tables-error',
});
errorsContainer.createDiv({
text: `- ${possibleMountContext}`,
cls: 'enhanced-tables-error',
});
return;
}
const [
yamlCodeEl,
configuration,
tableEl,
tableData,
indexOfTheEnhancedTable,
] = possibleMountContext as MountContext;
setTimeout(() => {
mountEnhancedTables(
this.app,
yamlCodeEl,
configuration,
tableEl,
tableData,
indexOfTheEnhancedTable,
);
}, 300);
}, 1);
}
}