saimcan
saimcan

Reputation: 1762

How to initialize CKEditor textarea line breaks as like html textarea line breaks

  1. 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).
  2. 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 ?

Upvotes: 2

Views: 1607

Answers (1)

sabithpocker
sabithpocker

Reputation: 15566

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

Upvotes: 2

Related Questions