Callback when markdown code block and editor is fully loaded

In the plugin I am currently developing i need a way to reliably get a reference to the MarkdownView and Editor from inside the MarkdownCodeBlockProcessor.

Currently I am using to achieve this. Hower I have found that when a note containing the code block is opened this call will not always return a MarkdownView. I am guessing that at that point the editor is not completely loaded yet.

Also at this point the “container” provided by the registerMarkdownCodeBlockProcessor is not part of the actual editor DOM yet and I need a way to check if the block is rendered in SourceMode, ReadMode or as an Embed.

If anyone knows how to register a callback for when the codeblock is loaded and how to determine the editor mode please tell me.

One workaround I have found is to use app.workspace.on("layout-change") but this is not reliable either.

Example Code:

this.registerMarkdownCodeBlockProcessor("testblock", (source, container, ctx) => {
  // this is sometimes null
  const mdv =;
  // parent is not yet available
  const parent = container.parentElement.parentElement;