源碼:
ace.js - https://link.jianshu.com/?t=https://github.com/ajaxorg/ace-builds.git
官網(wǎng)及API:
ace.js - https://link.jianshu.com/?t=https://github.com/ajaxorg/ace
在項(xiàng)目中只使用了它的代碼高亮功能,因?yàn)榈侥壳鞍姹距医荩С至顺^(guò)120多種的語(yǔ)法高亮绽淘,超過(guò)20多種主題等,在編輯器方面也支持多種操作,包括提示等,算是一個(gè)基于web端的代碼編輯器了狡刘。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<style type="text/css" media="screen">
.ace_editor {
/*position: relative !important;*/
border: 1px solid lightgray;
border-radius:5px;
margin: auto;
height: 800px;
width: 80%;
}
</style>
</head>
<body>
<div id="editor"></div>
<script src="ace-builds-master/src/ace.js"></script>
<script src="ace-builds-master/src-noconflict/ext-language_tools.js"></script>
<script>
//引入語(yǔ)言工具
ace.require("ace/ext/language_tools");
const editor = ace.edit("editor");
//選擇主題
editor.setTheme("ace/theme/twilight");
//選擇語(yǔ)言
editor.session.setMode("ace/mode/javascript");
//各項(xiàng)設(shè)置
editor.setOptions({
enableBasicAutoCompletion : true,
enableSnippets : true,
enableLiveAutocompletion : true
});
//預(yù)設(shè)值
if (typeof ace == "undefined" && typeof require == "undefined") {
document.body.innerHTML = "<p style='padding: 20px 50px;'>couldn't find ace.js file, <br>"
+ "to build it run <code>node Makefile.dryice.js full<code>"
} else if (typeof ace == "undefined" && typeof require != "undefined") {
require(["ace/ace"], setValue)
} else {
require = ace.require;
setValue()
}
function setValue() {
require("ace/lib/net").get(document.baseURI, function(t){
var el = document.getElementById("editor");
el.env.editor.setValue(t, 1);
})
}
</script>
</body>
</html>
所支持的功能襟诸,在官方提供的demo里都有瓦堵,具體的設(shè)置參數(shù)可翻看API。