I want to display html code in ace editor from load but the <!DOCTYPE>
, <html>
, <head>
and <body>
are not displayed. The line are blank in the editor.
<pre id="editor">
<!DOCTYPE HTML>
<html>
<head>
<title>my website</title>
</head>
<body>
<!--Add your heading tag below-->
</body>
</html>
I have also tried replacing the special characters but this code is displayed exactly as typed. The characters do not get converted to < etc
<pre id="editor">
<!DOCTYPE HTML>
<html>
<head>
<title>my website</title>
</head>
<body>
<!--Add your heading tag below-->
</body>
</html>
</pre>
The 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);
use escaped version and do not call setValue(text);
after ace.edit
or use text = el.textContent;
instead of innerHTML
.