The MarkdownPostProcessor that one registeres with registerMarkdownPostProcessor callback can be called in many different contexts.
For example:
- The active note is rendred (the most common)
- A plugin renders markdown with
MarkdownRenderer.render - User opens a preview popup of a note.
Getting the View via const view = app.workspace.getActiveViewOfType(View); assumes the post processor context is the opened note.
As in registerMarkdownCodeBlockProcessor callaback, you get additional parameters along with the MarkdownPostProcessorContext. Would be great if the View (which in most cases would be of type MarkdownView) would also be passed to the MarkdownPostProcessor, e.g.:
this.registerMarkdownPostProcessor((el, context, view) => {…});
If it isn’t possible to pass the View, the second best option is to make containerEl of MarkdownPostProcessorContext public. The el HTMLElement is not attached to the DOM when the MarkdownPostProcessor is called.
The primary use of passing the View/ItemView/…/MarkdownView would also be to access the containerEl or contentEl properties.