我一直在尝试将语法突出显示添加到我的网络应用程序并找到了 ace。但是,在使用文档中提供的解决方案后,我仍然无法更改编辑器主题。有谁知道该怎么做?
到目前为止,我只是用下面的代码初始化了元素
var editor = ace.edit("editor");
editor.getSession().setUseWrapMode(true);
editor.setHighlightActiveLine(true);
editor.setShowPrintMargin(false);
editor.setTheme('ace-builds-master/theme/tomorrow_night.css');
editor.getSession().setMode("ace/mode/javascript");
最佳答案
setTheme()
的构建模式参数不是路径而是主题的 id,因此您需要调用
.setTheme('ace/theme/tomorrow_night')
代替
请注意,您还可以使用一次调用设置所有选项
editor.setOptions({
useWrapMode: true,
highlightActiveLine: true,
showPrintMargin: false,
theme: 'ace/theme/tomorrow_night',
mode: 'ace/mode/javascript'
})
或者在带有 ace.edit 选项的新版本的 ace pass 对象中
var editor = ace.edit("editor"{
useWrapMode: true,
...
})
关于ace-editor - 如何在 Ace 编辑器中更改主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335866/