However, this task won't be done alone as ACE will not analyze the code to check the programming language of the providen text. In this article, you'll learn how to set the mode automatically
The following implementation would work well, in case you don't want to use the built-in module that make the things easier, to achieve this task:
However, you'll need to create a huge list in order to cover all the possible extensions and programming languages (in case you really want to implement this by yourself, you can check the source code of the ext-modelist file in Github to retrieve a complete list of extensions). So, what's the properly (and easy) way to do it? Just use the modelist extension of ACE editor that has already written all the possible file extensions and mode for ACE and you're ready to go.
modelist.js file is normally located in
src/ext-modelist.js, so you'll need to add it with a script tag in your document:
And then you'll be able to require it using
ace.require("ace/ext/modelist") according to the version of ACE that you're using:
If the previously snippet isn't enough for you, then see the source code of a demo using the modelist extension here in Github. Happy coding !