简体   繁体   English

如何突出显示codeMirror中的语法

[英]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. 我正在尝试将codemirror用于我的网站,这是一个用JavaScript实现的多功能文本编辑器。 But the syntax highlight is not working. 但语法高亮不起作用。 codeMirror Documentation didn't help me much. codeMirror文档对我没什么帮助。 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. 我在textarea中的代码语法不突出显示。 CodeMirror syntax highlighting is not working here. CodeMirror语法突出显示在这里不起作用。

You need to load the mode for the language you want to highlight. 您需要加载要突出显示的语言的模式。 In this case, load mode/javascript/javascript.js from the distribution. 在这种情况下,从分发加载mode/javascript/javascript.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM