Currently I use $('div#edit').froalaEditor('html.get')
to retrieve the html data inside editor, but it sucks when it es to process / store the text data in my backend because of all the p tags and &npsb; symbols in raw html string.
To be honest they do not even pass to the database without losing parts of the data. Is there a way or an api to directly extract the text data as a string with proper symbols like "\n\t
" from the froala editor?
Currently I use $('div#edit').froalaEditor('html.get')
to retrieve the html data inside editor, but it sucks when it es to process / store the text data in my backend because of all the p tags and &npsb; symbols in raw html string.
To be honest they do not even pass to the database without losing parts of the data. Is there a way or an api to directly extract the text data as a string with proper symbols like "\n\t
" from the froala editor?
-
Have you tried
$('div#edit').innerText
? See also stackoverflow./a/5002618/826983 – Stefan Falk Commented Oct 4, 2018 at 20:01
5 Answers
Reset to default 2If you dont like p tags you should use the enter option:
$('div#froala-editor-br').froalaEditor({ enter: $.FroalaEditor.ENTER_BR });
If you really would like to remove all tags you could use jQuery text method
jQuery($('div#edit').froalaEditor('html.get')).text()
Or you could use HTML options
var html = $('div#edit').froalaEditor('html.get') ; var div = document.createElement("div"); div.innerHTML = html; alert(div.innerText);
Here is the simplestst way to do it.
<textarea name="text"></textarea>
<script>
new FroalaEditor('textarea',{
heightMin: 400, // customize minimum hight
heightMax: 250 // customize maximum hight
});
</script>
or
<textarea id="editor" name="text"></textarea>
<script>
new FroalaEditor('#editor',{
heightMin: 400, // customize minimum hight
heightMax: 250 // customize maximum hight
});
</script>
if you are using post method or get method put this code into form and you get this data as a request.POST['text'].
There is http://textversionjs./ library which can be used to convert HTML to plain text. It also keeps new lines.
<script src="textversion.js"></script>
<script>
var html = $('div#edit').froalaEditor('html.get');
var text = createTextVersion(html);
</script>
Honestly, the easiest way to do this is
var body = $('#body').froalaEditor('html.get');
alert($(body).text());
You can use stringify() method in JSON to convert the HTML form to a text form.
<script>
var html = $('div#edit').froalaEditor('html.get');
var text = JSON.stringify(html)
</script>
And you can store them in any backend and use them later.