最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loading a HTML file into ACE Editor PRE Tag - Stack Overflow

programmeradmin2浏览0评论

There is a (on the server) locally stored HTML file which i need to show to user and allow use to make changes to it and save it. (Something like template file editor in wordpress).

For this I am using ACE Editor.

My javascript code:

$(document).ready(function() {

var editor = ace.edit("editor");

editor.getSession().setMode("ace/mode/html");
editor.setTheme("ace/theme/chrome");

editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");
editor.gotoLine(1);

});

Code in file abc.html

My Problem: Although I have used addslashes, there are some characters that cause problem. Isn't there a method to directly supply a file to ACE Editor?

Is there any other such editor which can directly be supplied a file name to open?

EDIT: SOLVED!

Instead of passing file text via setValue() function, I directly printed text within PRE tag

<pre id="editor"><?php echo htmlentities(file_get_contents($input_dir."abc.html")); ?></pre>

It worked.

There is a (on the server) locally stored HTML file which i need to show to user and allow use to make changes to it and save it. (Something like template file editor in wordpress).

For this I am using ACE Editor.

My javascript code:

$(document).ready(function() {

var editor = ace.edit("editor");

editor.getSession().setMode("ace/mode/html");
editor.setTheme("ace/theme/chrome");

editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");
editor.gotoLine(1);

});

Code in file abc.html

My Problem: Although I have used addslashes, there are some characters that cause problem. Isn't there a method to directly supply a file to ACE Editor?

Is there any other such editor which can directly be supplied a file name to open?

EDIT: SOLVED!

Instead of passing file text via setValue() function, I directly printed text within PRE tag

<pre id="editor"><?php echo htmlentities(file_get_contents($input_dir."abc.html")); ?></pre>

It worked.

Share Improve this question edited Feb 27, 2015 at 14:58 j08691 208k32 gold badges269 silver badges280 bronze badges asked Mar 3, 2013 at 14:13 RomitRomit 1062 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

the correct escaping is

htmlspecialchars(addslashes(file_get_contents("abc.html")));
editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");

is wrong. abc.html is out of php code. syntax error

editor.setValue('<?php echo addslashes(file_get_contents("abc.html")); ?>');

this could work. have not tested

发布评论

评论列表(0)

  1. 暂无评论