generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
40 lines (34 loc) · 856 Bytes
/
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
import {
App,
MarkdownPostProcessorContext,
parseYaml,
Plugin,
PluginSettingTab,
Setting,
} from "obsidian";
import { StatblockRenderer } from "statblockrenderer";
const srdData = require("monsters.json");
export default class ArchmagePlugin extends Plugin {
async onload() {
this.registerMarkdownCodeBlockProcessor(
"13a",
this.processMarkdown.bind(this)
);
}
async processMarkdown(
source: string,
el: HTMLElement,
ctx: MarkdownPostProcessorContext
): Promise<any> {
const yaml = parseYaml(source);
let renderData = { ...yaml };
if (yaml.monster) {
const lookupMonster = srdData.find((x) => x.name === yaml.monster);
if (lookupMonster) {
renderData = { ...lookupMonster, ...yaml };
}
}
ctx.addChild(new StatblockRenderer(el, renderData));
}
onunload() {}
}