generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.ts
24 lines (20 loc) · 930 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
import { MarkdownPostProcessorContext, Plugin } from 'obsidian';
import { PLAYBACK_CONTROLS_ID } from './cfg';
import { PlaybackElement } from './playback_element';
export default class MusicPlugin extends Plugin {
onload() {
this.registerMarkdownCodeBlockProcessor('abc', this.codeProcessor);
this.registerMarkdownCodeBlockProcessor('music-abc', this.codeProcessor);
// Although unused by us, a valid DOM element is needed to create a SynthController
const unusedPlaybackControls = document.createElement('aside');
unusedPlaybackControls.id = PLAYBACK_CONTROLS_ID;
unusedPlaybackControls.style.display = 'none';
document.body.appendChild(unusedPlaybackControls);
}
onunload() {
document.getElementById(PLAYBACK_CONTROLS_ID).remove();
}
async codeProcessor(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) {
ctx.addChild(new PlaybackElement(el, source));
}
}