王牌编辑不显示

时间:2016-02-21 21:13:17

标签: javascript html ace-editor

我想在加载的ace编辑器中显示html代码,但不会显示<!DOCTYPE><html><head><body>。编辑器中的行是空白的。

<pre id="editor">
<!DOCTYPE HTML>
<html>
<head>
    <title>my website</title>
</head>
<body>
<!--Add your heading tag below-->

</body>
</html>

我还尝试替换特殊字符,但此代码与键入的完全一样。字符不会转换为&lt;等

<pre id="editor">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;my website&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!--Add your heading tag below--&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>

javascript

el = document.getElementById("editor");
text = el.innerHTML;
editor = ace.edit(el);
editor.session.setValue(text);
editor.setTheme("ace/theme/custom");
editor.session.setMode("ace/mode/html");
editor.getSession().setUseWrapMode(true);
editor.setOptions({
    enableBasicAutocompletion: false,
    enableSnippets: false,
    enableLiveAutocompletion: false
});
editor.gotoLine(2);

1 个答案:

答案 0 :(得分:1)

使用转义版本,setValue(text);之后不要致电ace.edit 或使用text = el.textContent;代替innerHTML

相关问题