ace.js代码如何格式化
下面一段代码在粘贴代码到ace editor时触发格式化
var beautify = ace.require("ace/ext/beautify"); var editor = ace.edit("bfweditor"); editor.$blockScrolling = Infinity; editor.setTheme("ace/theme/chaos"); editor.session.setMode("ace/mode/html"); editor.setFontSize(18); editor.setOptions({ enableBasicAutocompletion : true, enableSnippets : true, enableLiveAutocompletion : true }); editor.on("paste", function(e) { setTimeout(function(){ beautify.beautify(editor.session); }, 500); });亲测,可用
有些人出现undefined,主要是没有引入ext-beautify.js库
<script src="http://domian.com/js/ace/ext-beautify.js"></script>
网友评论0