EpicEditor文本显示为而不是空格

时间:2012-11-04 16:47:29

标签: javascript html web.py mako epiceditor

我不确定这是否是一个实际问题,但我正在使用Epic Editor在我的GAE应用程序中输入并保存markdown(webpymako作为模板引擎)。

我在表单中有一个隐藏的输入元素,当我提交表单时会被EpicEditor的内容填充,但所有的空格都被 替换。这是预期的功能吗?如果我在EpicEditor网站上检查相同的代码,它显然会返回空格而不是 那么我的不同之处是什么?

<form>
<!-- form elements -->
<input id="content" name="content" type="hidden" value></input>
<div id="epiceditor"></div>
<button type="submit" name="submit" id="submit">submit</button>
</form>

<script type="text/javascript">
    $('button#submit').click(function(){
        var content = editor.getElement('editor').body.innerHTML; //all the spaces are returned as &nbsp; and breaks are <br>
        $('input#content').html(content);
    });
</script>

注意:我想在我的数据存储的TextProperty字段中将我的内容保存为markdown,并在使用marked.js检索它时生成html标记

3 个答案:

答案 0 :(得分:5)

我是EpicEditor的创造者。你不应该得到innerHTML。在你写的时候,EpicEditor对innerHTML没有任何作用。您看到的文本和代码在所有浏览器之间会有所不同,这就是contenteditable字段的工作方式。例如,某些浏览器会为某些&nbsp空格插入UTF-8字符。

EpicEditor为您提供了标准化文本的方法。您不应该尝试手动解析文本。

$('button#submit').click(function(){
    var content = editor.exportFile();
    $('input#content').html(content);
});

有关exportFile的更多详情:http://epiceditor.com/#exportfilefilenametype

P.S。您不需要输入#content。这和#content一样:)

答案 1 :(得分:1)

如果你找不到原因,你可以这样做:

<script type="text/javascript">
    $('button#submit').click(function(){
        var content = editor.getElement('editor').body.innerHTML; 
        content = content.replace("&nbsp;", " ");
        $('input#content').html(content);
    });
</script>

答案 2 :(得分:0)

[编辑:已解决] 我不应该使用innerHTML,而应使用innerText


我发现Epic Editor在第一个进程的所有空间都使用了&nbsp;。据推测,这是一个功能。

然而,这不是问题。所有空格都被转换为&nbsp;,最终,我意识到当Epic Editor从localStorage加载自动保存的内容时会发生这种情况。

我现在每次都从我的后端加载内容而不是自动保存。不是最佳的,但解决了它。