Rendering events or Force Rendering?

Hi, I’m trying to make my own code block enhancement plugin for Obsidian.

I make a markdown post processor to do so, referencing other famous code block enhancement community plugins like Better Code Block plugin and Code Block Enhancer.

But it seems like markdown post processors work once when the markdown note(source view) is rendered to HTML(reading view) for the first time after the vault has been opened. I think it is happening because Obsidian keeps some kind of HTML(reading view) cache for the performance.

So here’s my question. Is there an event triggered when the markdown note(source view) has been changed? I may register listener to re-render the whole markdown(or hopely only code blocks) to HTML(reading view) if such thing exists. Or, is there an API that can force re-rendering markdown(or hopely only code blocks) to HTML(reading view)?

I have the same problem. I will trigger a re-rendering of the complete preview (reading view) or a re-rendering for special lines of the markdown view.

Did you solve your problem ? Have you any ideas (using statefields) ?

Me too

Did anyone solve this issue in the meanwhile ?

Is there an event triggered when the markdown note(source view) has been changed?

If “change” means modification of the file content, you can use this.app.vault.on("modify", ...)
But in this case, I think the markdown is re-rendered automatically, at least when the code block that is the target of the post-processor is modified.

If it means the event where the user switches from one note to another note, you can use this.app.workspace.on("active-leaf-change", ...)

is there an API that can force re-rendering markdown(or hopely only code blocks) to HTML(reading view)?

You can use this:

const view = this.app.workspace.getActiveViewOfType(MarkdownView);
view.previewMode.rerender(true);