Autoload module with GFM code fences


#1

Hello there, and thanks for this awesome piece of code!

I’m building a little application using the GFM mode. I saw that GFM can highlight code in fenced code blocks (well, actually it seems the markdown mode is doing the job, but anyway), and it works great if the mode was already loaded.

But I wonder if I can load these modes on-the-fly, as the users could write any kind of code in these fenced blocks, and I don’t really want to load them all when they are not used. I tried to trace the calls to Markdown.getMode and see if I could use the loadmode module, but I’m not a skilled JS programmer and didn’t really understand how that module work and if I could integrate it in getMode. Maybe I’d better rely on requirejs only, but not sure if it can operate in a synchronous way.

Do you have any idea? Maybe someone has already tackled that problem, but I couldn’t find anything on internet.

Well, thanks for any help you could give me. :slight_smile:

Cilyan


#2

This isn’t current possible – there’s no hook that will report when a mode is requested, and even if there were, loading a mode will be asynchronous, whereas the markdown mode will request the mode synchronously. You could do something where you scan the document for code blocks that declare their language outside of the mode, trigger loading of the required modes, and reset the editor’s mode option when they finish loading to force a re-highlight.


#3

Oh, too bad! Maybe in the future? Thanks for the reply, I’ll enjoy CM anyway!