javascriptcodemirror

How to highlight syntax in codeMirror


I am trying to use codemirror to my website a versatile text editor implemented in JavaScript for the browser. But the syntax highlight is not working. codeMirror Documentation didn't help me much. here is my code.

<html>
<head>
<meta charset="utf-8">
<title>Code Mirror</title>
<link rel="stylesheet" type="text/css" href="codemirror.css">
<script type="text/javascript" src="codemirror.js"></script>
</head>

<body>

    <textarea id='demotext'>

    function foo() {
        for(i = 0, i < 10, i++)
        console.log(i);
    }

    </textarea>

<script type="text/javascript">

    var editor = CodeMirror.fromTextArea(document.getElementById("demotext"), {
          lineNumbers: true,
          mode: "javascript"
    });

</script>
</body>
</html>

my code syntax inside textarea is not highlighting. CodeMirror syntax highlighting is not working here.


Solution

  • You need to load the mode for the language you want to highlight. In this case, load mode/javascript/javascript.js from the distribution.