【发布时间】:2014-01-19 03:13:34
【问题描述】:
我可以让mode/javascript 与:
JS
https://github.com/ajaxorg/ace-builds/blob/master/src-noconflict/ace.js
主题
https://github.com/ajaxorg/ace-builds/blob/master/src-noconflict/theme-tomorrow.js
模式
https://github.com/ajaxorg/ace-builds/blob/master/src-noconflict/mode-javascript.js
工人
https://raw.github.com/ajaxorg/ace-builds/master/src-noconflict/worker-javascript.js
HTML
<script src="/static/js/ace/ace.js"></script>
<div class="my_ace_editor">
function foo(items) {
var x = "All this is syntax highlighted";
return x;
}
</div>
CSS
#my_ace_editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
jQuery
$(document).ready(function() {
var editor = ace.edit("my_ace_editor");
editor.setTheme("ace/theme/tomorrow");
editor.getSession().setMode("ace/mode/javascript");
});
但是在尝试显示 HTML 时没有任何运气:
HTML
<div id="my_ace_editor"><p>test</p></div>
jQuery
$(document).ready(function() {
var editor = ace.edit("my_ace_editor");
editor.setTheme("ace/theme/tomorrow");
editor.getSession().setMode("ace/mode/html");
});
并已添加:
https://raw.github.com/ajaxorg/ace-builds/master/src-noconflict/mode-html.js
如果我在 HTML 编辑器中输入,标签和内容会应用语法高亮显示。
但它在加载时并没有显示实际的 HTML - 它只显示test。
没有 Firebug 错误,我可以看到应该在 Firebug 中突出显示的实际 HTML。
是否需要其他文件或设置?
编辑:如果我使用,我可以在 Ace 编辑器中正确显示 HTML 内容:
editor.setValue("<html>test</html>",-1);
但我需要能够从 HTML 本身而不是在 jQuery 中设置值。
内容正在从数据库中加载(即它是“动态内容”),我不确定这是否会有所不同?
【问题讨论】:
标签: ace-editor