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

javascript - EpicEditor text showing as   instead of space - Stack Overflow

programmeradmin1浏览0评论

Not sure if this is an actual problem per se but I'm using Epic Editor to input and save markdown in my GAE application (webpy with mako as the templating engine).

I've got a hidden input element in the form which gets populated by the EpicEditor's content when I submit the form but all the white spaces are replaced by  . Is this an intended feature? If I check the same code on the EpicEditor site, it clearly returns spaces instead of   so what's different about mine?

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

NOTE: I want to save my content as markdown in a TextProperty field my data store and generate the html tags when I retrieve it using marked.js

Not sure if this is an actual problem per se but I'm using Epic Editor to input and save markdown in my GAE application (webpy with mako as the templating engine).

I've got a hidden input element in the form which gets populated by the EpicEditor's content when I submit the form but all the white spaces are replaced by &nbsp;. Is this an intended feature? If I check the same code on the EpicEditor site, it clearly returns spaces instead of &nbsp; so what's different about mine?

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

NOTE: I want to save my content as markdown in a TextProperty field my data store and generate the html tags when I retrieve it using marked.js

Share Improve this question edited Jan 27, 2013 at 11:29 Oscar Godson 32.8k42 gold badges125 silver badges206 bronze badges asked Nov 4, 2012 at 16:47 sw00sw00 9802 gold badges16 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

I'm the creator of EpicEditor. You shouldn't be getting the innerHTML. EpicEditor does nothing to the innerHTML as you write. The text and code you are seeing will be different between all the browsers and it's how contenteditable fields work. For example, some browsers insert UTF-8 characters for spaces some &nbsp.

EpicEditor gives you methods to normalize the text tho. You shouldn't ever be trying to parse the text manually.

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

More details on exportFile: http://epiceditor./#exportfilefilenametype

P.S. You don't need to do input#content. Thats the same as just #content :)

You can do this if you dont find out why:

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

[EDIT: solved] I shouldn't be using innerHTML, but innerText instead.


I figured out that Epic Editor uses &nbsp; on all spaces proceeding the first one. This is a feature, presumably.

However that wasn't the problem. ALL the spaces were being converted to &nbsp;, eventually, I realised it occurs when Epic Editor loads the autosaved content from localStorage.

I'm now loading content from my backend every time instead of autosaving. Not optimal, but solves it.

发布评论

评论列表(0)

  1. 暂无评论