deathau / cm-editor-syntax-highlight-obsidian

A plugin for [Obsidian](https://obsidian.md) which allows syntax highlighting for code blocks in the editor.
499 stars 37 forks source link

trigger auto refresh #3

Closed jdbrice closed 4 years ago

jdbrice commented 4 years ago

thanks for the plugin. If a note is open in edit mode with code when obsidian starts it does not work (shows all white text) until toggling from edit->preview->edit.

You can trigger an update on the active leaf with something like this:

const view = this.app.workspace.activeLeaf.view as MarkdownView;
const editor = view.sourceMode.cmEditor;
// editor.refresh(); //  DOESNT DO ANYTHING
editor.setOption("mode", "css");
editor.setOption("mode", "markdown");

i.e. by swapping the mode from markdown and then back. Maybe this can be applied in the onload()?