Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 828
PariSh KhAn Avatar asked Nov 02 '15 21:11

PariSh KhAn


1 Answers

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

like image 129
Marijn Avatar answered Oct 20 '22 15:10

Marijn