如何在codeMirror中高亮语法

How to highlight syntax in codeMirror

我正尝试在我的网站上使用 codemirror 一个在 JavaScript 中为浏览器实现的多功能文本编辑器。但是语法突出显示不起作用。 codeMirror 文档对我帮助不大。这是我的代码。

<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>

我在 textarea 中的代码语法没有突出显示。 CodeMirror syntax highlighting is not working here.

您需要加载要突出显示的语言的模式。在这种情况下,从分发中加载 mode/javascript/javascript.js