the code snippets in markdown file cannot be highlighted properly after loading the necessary mode at run time!

version: 5.65.2

codepen: https://codepen.io/tinywisp/pen/jOaXqqq

screenshot:
image

description:

I wanted to load the javascript mode at run time.

Before the javascript mode was loaded, the code snippet in the editor was handled as plain text, and it was all right!

When the script finished loading the javascript mode, I copy the code snippet and paste it into the editor. I found that the first code snippet was not highlighted correctly, while the second code snippet was highlighted perfectly.

I tried to call the refresh() method, but it didn’t work.

After your mode finished loading, call setOption("mode", ...) again (with the same mode) to force re-highlighting.

1 Like

It works! Thanks!