CodeMirror是一款开源的在线代码编辑器,基于Javascript,体积小巧,支持实时在线代码高亮显示,自动补全、自动缩进、智能提示等功能。丰富的API与CSS主题系统,方便拓展和嵌入到自定义程序中。
使用范例:
下载CodeMirror,然后在网页中可直接引入。如下代码即实现了一个可以高亮显示Java代码的编辑器:
<!--
最简单的CodeMirror编辑器
-->
<!DOCTYPE
html>
<html>
<!--下面两个是使用Code Mirror必须引入的-->
<link rel="stylesheet" href="codemirror-5.12/lib/codemirror.css">
<script src="codemirror-5.12/lib/codemirror.js"></script>
<!--Java代码高亮必须引入-->
<script src="codemirror-5.12/clike.js"></script>
<head>
<title>CodeMirrorTest</title>
</head>
<body>
<textarea id="code"></textarea>
</body>
<script type="text/javascript">
//根据DOM元素的id构造出一个编辑器
var editor=CodeMirror.fromTextArea(document.getElementById("code"),{
mode:"text/x-java" //实现Java代码高亮
});
</script>
</html>
[repo owner=”codemirror” name=”CodeMirror”]
-----------------------------------------------------------------
In-browser code editor (version 5, legacy)
CodeMirror
CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with over 100 language modes and various addons that implement more advanced editing functionality. Every language comes with fully-featured code and syntax highlighting to help with reading and editing complex code.
A rich programming API and a CSS theming system are available for customizing CodeMirror to fit your application, and extending it with new functionality.
You can find more information (and the manual) on the project page. For questions and discussion, use the discussion forum.
See CONTRIBUTING.md for contributing guidelines.
The CodeMirror community aims to be welcoming to everybody. We use the Contributor Covenant (1.1) as our code of conduct.
Installation
Either get the zip file with the latest version, or make sure you have Node installed and run:
npm install codemirror
NOTE: This is the source repository for the library, and not the distribution channel. Cloning it is not the recommended way to install the library, and will in fact not work unless you also run the build step.
Quickstart
To build the project, make sure you have Node.js installed (at least version 6)
and then npm install
. To run, just open index.html
in your
browser (you don't need to run a webserver). Run the tests with npm test
.
from https://github.com/codemirror/codemirror5
No comments:
Post a Comment