问题
- HTML textareas can recognize line breaks (enter button) and i can save the element's text value into database. Then i can get those data, set it on any textarea, i still have line breaks (no problem until here).
- CKEditor textarea puts
<p>
or<br />
after line breaks. When i remove these tags, CKEditor cannot recognize there's a line break.
Purpose : I'm using a word counter plugin with CKEditor, so i need to use CKEditor as like a textarea. I need the plain text value.
I tried these so far :
CKEDITOR.instances.editor1.document.getBody().getText()
Yes i can get the text value correctly, i put this value on DB, but when i reload my page, the line breaks are gone. Because ckeditor works only with html tags ?
config.autoParagraph = false;
This one just removes the <p>
tag at the beginning of the content.
I need plain text+line breaks that's it. Any suggestions ? Or should i write down my own classes ?
回答1:
Array.prototype.map
.call(CKEDITOR.instances.editor1.document.getBody().$.childNodes,
function(item){
return item.innerText;
})
.join("\n");
Just a crazy answer to convert <p>
blocks to a string separated by \n
来源:https://stackoverflow.com/questions/33104421/how-to-initialize-ckeditor-textarea-line-breaks-as-like-html-textarea-line-break