2012-11-04 41 views
2

不确定这是否是实际问题,但我正在使用Epic Editor在我的GAE应用程序中输入并保存降价(webpymako作为模板引擎)。EpicEditor文本显示为 而不是空格

当我提交表单时,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场我的数据存储和生成的HTML标记时,我检索使用marked.js

回答

5

我是EpicEditor的创造者。你不应该得到innerHTML。 EpicEditor对你写的innerHTML没有任何帮助。您看到的文本和代码在所有浏览器中都不相同,这是contenteditable字段的工作原理。例如,一些浏览器插入UTF-8字符的空格&nbsp

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

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

更多细节:http://epiceditor.com/#exportfilefilenametype

附:你不需要做输入#内容。这就像#content :)

+0

另外,请注意,随着EpicEditor的发展,编辑器HTML中会有更多的标记可能会添加功能,右键单击菜单等,所以不要依赖HTML内部。 –

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> 
0

[编辑:解] 我不应该使用innerHTML,但innerText代替。


我想通了,史诗编辑器使用&nbsp;继续上的第一个所有空间。据推测,这是一个功能。

但是,这不是问题。所有的空间都被转换为&nbsp;,最终,我意识到它发生在Epic编辑器从localStorage加载自动保存的内容时。

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

+1

查看我的回答。你让它比它更难:) –

+0

谢谢@OscarGodson! – sw00