Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract plain text from ckeditor generated html in JAVA

I am using ckeditor to compose the emails, I am using the html generated by it to send the html emails ad i also need the text version also, So having both html and plain text version in emails will avoid the spam.

What is the way to get the text from ckeditor html code in java.

like image 532
n92 Avatar asked Dec 11 '22 17:12

n92


1 Answers

This is quite simple JavaScript call:

CKEDITOR.instances.yourEditorInstance.getData() 

Returns:

<h1>Apollo 11</h1>    
<p><b>Apollo 11</b> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong" title="Neil Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin" title="Buzz Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p>

However:

CKEDITOR.instances.yourEditorInstance.editable().getText() 

Returns:

Apollo 11
Apollo 11 was the spaceflight that landed the first humans, Americans Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.
like image 165
oleq Avatar answered Dec 27 '22 04:12

oleq