I see that there is an argument named “context” when we use RegisterMarkdownPostProcessor. I wish to know what is it used for or how can i use it? any idea?
Can i use it to retrieve the block source later in the function calls without passing the source or element in all the functions?
this.registerMarkdownPostProcessor((element, context) => {
console.log("callback called");
});
joethei
February 21, 2024, 7:43am
2
ctx.addChild is usually accessed to provide a lifecycle management for child components, AFAIK
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();
}
This file has been truncated. show original